1

How to be redirected from "Edit Form", after clicking Save button, to the "Display Form" of the already edited/modified Item? Presently it redirects me to the entire list view and I have to search for the item to open it again.

3 Answers 3

0

You can try something like this

$(document).ready(function() {
     var button = $("input[id$=SaveItem]");
    // change redirection behavior
    button.removeAttr("onclick");
    button.click(function() {
        var elementName = $(this).attr("name");
        var aspForm = $("form[name=aspnetForm]");
        var oldPostbackUrl = aspForm.get(0).action;
        var currentSourceValue = GetUrlKeyValue("Source", true, oldPostbackUrl);
        var newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, "MyRedirectionDestination.aspx");

        if (!PreSaveItem()) return false;
        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));
    }); 
});

Read more here

I did not test the solution.

0

A twisted-thinking idea..

You could, on the AllItems page, check in the document.referrer, if you came from a New Form, then use JavaScript to get the recent ID and do a redirect

If your AllItems View is sorted with the latest entry first it can be as easy as as puttin a CEWP below the ListView or a OnPostRender CSR script:

if(document.referrer.search('NewForm.aspx')>0){
   document.location="DispForm.aspx?ID=" + ctx.ListData.Row[0].ID
}
0

On Sharepoint 2013 the above methods didn't work porperly. Based on this blog post I've been able to setup the below solution (in vanilla javascript):

var elems = document.querySelectorAll('input[id$="SaveItem"]');
var redirectTo = "https://my.website.com/site/something/Pages/Wait.aspx";
for (var i=0; i<elems.length; i++) {
  // overwrite "STSNavigate()" when clicking on the save button
  elems[i].setAttribute("onclick", "STSNavigate = function(){ window.location.href = '" + redirectTo + "' }; " + elems[i].getAttribute("onclick"))
}

My form is not opening into a modal. If you open it into a modal, you may have to add the below code:

// force PostBackRequired to true in the context, otherwise it won't work if you open it into a modal
WPQ2FormCtx.PostBackRequired=true;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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