SharePoint – Publishing Page Validation

Hi Everyone,
Today new issue and solution 🙂 small article but since it took time to solve me so thought to share.
Background: I have a Publishing page layout on which I have some custom fields. For these fields I need to have a validation. So, I used PreSaveItem() function in my JavaScript code for validation but it only works on NewForm.aspx and EditForm.aspx pages in SharePoint and not on publishing page.
Solution:
- If you inspect Save button on publishing page. You will find that CoreInvoke() function is getting called on button click as shown in fig.

- We have to override CoreInvoke() method.
CoreInvoke = function(action, target) - This method should be executed when user click Save button on when publishing page is in edit mode.
- Put the following code in your js. The code should be executed only when action is PageActionClick.
//override the CoreInvoke function
CoreInvoke = function (action, target)
{
If(action == ‘PageActionClick’)
{
//Your validation code here
If($(“input[type=’radio’]:checked”).length == 0)
{
alert(‘No radio button selected’);
return false;
}
else
{
// ooBCoreInvoke function here to save form
ooBCoreInvoke(action, target);
}
}
}
- This way you can have publishing page validation using JavaScript.
Thanks for reading
Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more. If you have any suggestion / feedback / doubt, you are most welcome.
Stay tuned on Knowledge-Junction
good