5

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

  • With which version of SharePoint do you want to use CSR? – Dikesh Gandhi Feb 8 at 4:07
2

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.

  • Thanks Joe. I think I could have gotten this to work but so many other things were affected by using the CSRListForm that I decided not to use it. – Ice Cube Mar 11 at 19:32
  • 1
    You're welcome. I knew by the time I saw it that you had already moved on to an hillbilly forms, but figured I'd share what I knew. – Joe McShea Mar 12 at 18:28
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.