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;
     }
});
2
  • Are you very sure the original onclick event is on this exact DOM element? Commented Jul 2, 2016 at 19:14
  • 1
    you should using PreSaveAction() for your validate.
    – user56733
    Commented Jul 4, 2016 at 4:42

1 Answer 1

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.

1
  • Thanks. Using PreSaveAction was my first thought but i don't think it is available in Page Layout Edit Mode. Commented Jul 4, 2016 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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