I want to perform some validation when a user click the save button on the SharePoint ribbon and cancel the submission of the form if it is not valid.
I am using a page layout in SharePoint 2013. The fields come from the page layout content type.
The id of the button is Ribbon.EditingTools.CPEditTab.EditAndCheckout.SaveEdit-SelectedItem
I tried without success:
add an onclick handler on the button
var saveButton = function () { return document.getElementById("Ribbon.EditingTools.CPEditTab.EditAndCheckout.SaveEdit-SelectedItem"); } $(saveButton()).removeAttr("onclick"); $(saveButton()).click( function(ev){ ev.preventDefault(); ev.returnvalue=false; // for IE only return false; } );
replace the onsubmit attribute of the form
$("form").attr("onsubmit","javascript: return false;")
Both codes are happily ignored by sp2013!