1
votes

I am using Sharepoint online 2015. During creating a list item, I need to save the list item and redirect the page to EditForm.aspx of the created list item instead of AllItems.aspx.

Following is the html code for the button:

<button type="button" id="idSaveProceed">Save & Proceed</button>

Following is the jQuery code for saving the list item and redirecting it to Edit form:

$("#idSaveProceed").click(function(event){
         event.preventDefault();
        if (!PreSaveItem()) return false;
        if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')) return false;
        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", "", false, true));

        GetListItemId(); // This will redirect the page to EditFoem.aspx;
    });

But when the code if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')) executes, the page redirect is happening to AllItems.aspx. I have even given custom url in WebForm_DoPostBackWithOptions. But before that code get executed, page is getting redirected.

I have tried using event.preventdefault() but of no use.

Kindly let me know what am missing here. Thanks in advance.

Note: I do not want to use InfoPath. I just want a solution in jQuery to handle this.

3
Did you add event.preventDefault as the first statement?Karl Gjertsen
Yes I have. Its been updated now.Naren
Are you setting a URL in your form tag?Karl Gjertsen
event.preventDefault()yjs

3 Answers

3
votes

You need to also update the

    < form id="aspnetForm" action="< url >?Source=...">

source parameter

Check out this url. http://formsdesigner.blogspot.in/2013/04/redirect-after-sharepoint-form.html

But just curious how are you going to get the newly submitted item id?

1
votes

You are posting the form in the client manager statement.

This will call the server side code and not go to the next line.

You could send the form post call using an Ajax call and then redirect the page.

0
votes

just return false in the end of click event

$("#idSaveProceed").click(function(event){
if (!PreSaveItem()) return false;
if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')) return false;
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", "", false, true));return false;});