Naren
Naren

Reputation: 1350

Unable to prevent page redirect after form submit

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.

Upvotes: 1

Views: 2905

Answers (3)

Nikunj
Nikunj

Reputation: 556

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?

Upvotes: 3

Ashiqullah Sahibzai
Ashiqullah Sahibzai

Reputation: 166

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;});

Upvotes: 0

Karl Gjertsen
Karl Gjertsen

Reputation: 4928

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.

Upvotes: 1

Related Questions