Redirect after Submit form (CSR)

The SharePoint form redefines CSR (client-side rendering).

I tried adding a new button, which is pretty much like the Save button, except that it redirects another form with the given parameters.

The fact is that the redirect does not work. I tried redirecting by changing the "action" property of the form, but it doesn't seem to count as a count.

Here is the new button: <input id="custom_addLine" type="button" name="custom_addLine" value="+" class="ms-ButtonHeightWidth">

Here is the function called by the button and the addLine method, as follows:

 $('#custom_addLine').click(function(event){ event.preventDefault(); addLine(getQueryStringParameter('ID')); }); function addLine(id) { if(!PreSaveItem()) { return false; } var actionUrl = "/Lists/PurchaseRequestLine/NewForm.aspx?PurchaseRequestID="+ id; var encodedActionUrl = encodeURIComponent(actionUrl); var newFormAction = location.pathname + '?Source=' + encodedActionUrl; $('#aspnetForm').attr('action',newFormAction); if(SPClientForms.ClientFormManager.SubmitClientForm('WPQ1')){ return false; } WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('custom_addLine', "", true, "", "", false, true)); } 

getQueryStringParameter is a custom function to retrieve parameters from a URI (which works).

The tricky part is that I want to keep the default action URI if the "Save" button is clicked, so the action parameter has been changed on the fly.

+5
source share
2 answers

You can change the Source attribute directly from the source action:

  function addLine(id) { if(!PreSaveItem()) { return false; } var oldActionUrl = $('#aspnetForm').attr('action'); var oldSource = GetUrlKeyValue("Source", true, oldActionUrl); var newSource = "/Lists/PurchaseRequestLine/NewForm.aspx?PurchaseRequestID="+ id; var newActionUrl = oldActionUrl.replace(oldSource, encodeURIComponent(newSource)); WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('custom_addLine', "", true, "", newActionUrl, false, true)); } 
+4
source

Please delete event.preventDefault (); from your code, it is responsible for redirection, does not work

 $('#custom_addLine').click(function(event){ addLine(getQueryStringParameter('ID')); }); 
+2
source

All Articles