1

am having an editform.aspx page in my SPO site. am using presaveitem() in my content editor web part to perform validation and etc after completion of calling of presaveitem(), i ant to stay on the same page , ie, i wanna stay like : https://mycustomersposite/msite/lists/splist1/editform.aspx?ID=425 with the same ID, after refreshing the page automatically.

 function Presaveitem()
 {  
 //perform validation .. etc 

   alert("Item is updated successfully on 11/05 monday");
   alert('reloading the page');
    window.location.reload();

return true;
}


The problem am facing is, after click on the save button, its automatically redirecting to the AllItems.aspx page always. what my understanding is if i call just before closing of Presaveitem() fun.call
window.location.reload(); , it will reload the page with the latest updates happened to the list items id , mentioned in the ?ID=mylistitemidnumber . How to stop redirecting to the allitems.aspx page from editform? is it possible to add a ?source param in the URL, ( inject it on page load) automatically/programmatically?

  • First of all, the meaning of presaveitem is that it is called before saving the item. Why would you write saving functionality inside presaveitem? There are multiple ways to achieve it. Do you have the freedom to edit the forms in designer? – harshal gite Nov 5 '18 at 17:38
  • @harshal, if i create a new custom form in SP designer, what i have observed that, i am unable to add a content editor wbe part in that custom form. its showing weird behaviour. so, i thought of using the existing,default newform, editform pages – dasarp Nov 6 '18 at 11:17
  • "there are multiple ways to achieve it." --> can you please elaborate it and what are the ways to achieve it. help is appreciated! – dasarp Nov 6 '18 at 11:19
  • If you sant to use the default form, then you can override the submit button action and redirect after saving. – harshal gite Nov 6 '18 at 11:22
1

Please find the screenshot of edit page with script editor web part and after addming the web part how your edit form URL looks likeThis block of code helped me in the past. Add a script editor on the edit form and paste the code in the script editor web part.

<script>
$(document).ready(function(){
    window.history.pushState("object or string", "Title",window.location.href+"?Source=http://YourPageURL");
});
</script>
  • are you saying that, just before closing the presaveitem(), i dont need to reload the page --> no need to call .reload()?? – dasarp Nov 5 '18 at 10:04
  • 1
    After the source attribute, use edit form url, it will reload the current page. you should use exact the following line of code. window.history.pushState("object or string", "Title", window.location.href+"?Source="+window.location.href); – Dhaval Nayi Nov 5 '18 at 10:25
  • after adding your code, it seems, the values are not getting saved into the splist. it loaded with the old values. i think, its not committing in the DB. – dasarp Nov 5 '18 at 11:15
  • I tried it with my splist and it worked well for me please see the screenshot attached – Dhaval Nayi Nov 5 '18 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.