CSRListForm and PreSaveAction or PreSaveItem
-
05-02-2021 - |
Вопрос
I've used PreSaveAction
successfully in the past, but now I'm working with a CSRListForm
and neither one of these will fire off. Even if I use just a simple alert message.
I know the CSRListForm
causes a lot of standard things to not work. Does it invalidate PreSaveAction
and PreSaveItem
as well?
Thanks
Edit:
Sharpoint 2016 On Prem
I'm saving using this method:
SPClientForms.ClientFormManager.SubmitClientForm('WPQ2');
The standard Save button has disappeared so I can't use this:
$('input[value=Save]').click();
My code is based off of this:
https://code.msdn.microsoft.com/office/CSR-code-samples-11-Fully-54ebcaa6
Thank you
Решение 2
After fighting with this for a few days I decided to abandon the CSRListForm method and use the hillbilly.js method specified here:
https://github.com/mrackley/HillbillyTemplate
With this method the following all work:
Standard Save and Cancel; Attach File; PreSaveItem; PreSaveAction
Другие советы
The problem you were having is because you weren't using the standard save button. The standard save button looks kind of like this:
<input name="somereallylongname" value="Save"
onclick="if (!PreSaveItem()) return false;if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')) return false;//etc"
id="somereallylongname"
target="_self" type="button">
Notice that the onclick
event starts with if(!PreSaveItem()) return false;
, and then it does if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')) return false;
. You said you're doing:
SPClientForms.ClientFormManager.SubmitClientForm('WPQ2');
to save the form, but that's only a portion of the logic, removing much of the validation. If you had done:
if (!PreSaveItem())
return false;
if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2'))
return false;
from your own button, validation would have worked the way you expected, including PreSaveItem. All OOB forms in 2016 are CSR forms, and they still work fine with PreSaveItem/PreSaveAction.