1

I have an article page where I need to do some custom validations in Edit mode(page layout). I am trying to cancel the save action using return false but the page is still saved.

$('span[id="Ribbon.EditingTools.CPEditTab.EditAndCheckout.SaveEdit-Large"]').click(function(){
        //validations
     if(//validationsfail){
      return false;
     }
});
| improve this question | | | | |
  • Are you very sure the original onclick event is on this exact DOM element? – Danny '365CSI' Engelman Jul 2 '16 at 19:14
  • 1
    you should using PreSaveAction() for your validate. – user56733 Jul 4 '16 at 4:42
1

Subscribing to the click events is not a good idea here, for many reasons (including: you'd have to consider all buttons user can press to validate the page (in ribbon, in the page...), key events, and also your Handler may happen after the SharePoint handler).

The good practice here, to intercept the save action and possibly cancel it, is to define a function called PreSaveAction. It will be automatically called by SharePoint before posting the data to the server. See for instance http://www.ilikesharepoint.de/2014/06/sharepoint-presaveaction-helps-for-actions-before-saving-an-item/ or http://sympmarc.com/2009/05/28/validation-on-sharepoint-forms-part-four/ for an example.

| improve this answer | | | | |
  • Thanks. Using PreSaveAction was my first thought but i don't think it is available in Page Layout Edit Mode. – Thomas Mathew Jul 4 '16 at 7:02

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.