Hi.
I have a task in Sharepoint 2013 to add to standard adding and editing forms the "Apply" button. After you click on it you need to save the data and remain on the form. The standard save buttonshould be left on the form, so I ruled out the option to simply replace the Source parameter in the URL.
First, I wanted to deal with the edit form.
What are the options I've tried and what you're facing:
On the form I added a web part in which the linked javascript.
I copied the "Save" button, which has the following form:
<input type="button" name="ctl00$ctl40$g_06d7dccf_c05b_4800_a59e_1eff3a633045$ctl00$toolBarTbl$RightRptControls$ctl00$ctl00$diidIOSaveItem" value="Сохранить" onclick="if (!PreSaveItem()) return false;if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')) return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl40$g_06d7dccf_c05b_4800_a59e_1eff3a633045$ctl00$toolBarTbl$RightRptControls$ctl00$ctl00$diidIOSaveItem", "", true, "", "", false, true))" id="ctl00_ctl40_g_06d7dccf_c05b_4800_a59e_1eff3a633045_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_diidIOSaveItem" accesskey="O" class="ms-ButtonHeightWidth" target="_self">1. When the form is loaded I have added the save button replacing the "SaveItem" to "CommitItem" in the parameters name, id, and onclick. And added the option to redirect to the current page.
<input type="button" name="ctl00$ctl40$g_06d7dccf_c05b_4800_a59e_1eff3a633045$ctl00$toolBarTbl$RightRptControls$ctl00$ctl00$diidIOCommitItem" value="Сохранить" onclick="if (!PreSaveItem()) return false;if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')) return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl00$ctl40$g_06d7dccf_c05b_4800_a59e_1eff3a633045$ctl00$toolBarTbl$RightRptControls$ctl00$ctl00$diidIOCommitItem','',true,'','" + this.location.href + "',false,true))" id="ctl00_ctl40_g_06d7dccf_c05b_4800_a59e_1eff3a633045_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_diidIOCommitItem" accesskey="O" class="ms-ButtonHeightWidth" target="_self">This decision led to the fact that the data was not saved, but the redirect was performed, the form remained updated information, but if I close the form and again opened a data item was old.
2. I decided to try a different approach. On onclick I change the current URL and cause a click on the save button:
window.history.pushState("", "", this.location.href.replace(oldSource, newSource));savebtn.click();window.history.replaceState("", "", this.location.href.replace(oldSource, newSource));savebtn.click();In this case, all remained, but was redirected to a list of all elements.
3. I saw the option of adding this button:
<input type=”button” value="Submit” name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={_MyURL_}')}" />But I have error: Uncaught ReferenceError: GenFireServerEvent is not defined at HTMLInputElement.onclick
What I did wrong or what approach can you tell me for my problem?