The following OnLoad Event JS code disables the Save button until changes are made on the Edit page. This can be especially helpful in minimizing premature submissions when the user interrupted.
// Disable the save button on page load
var saveButton = pageObj.getItemButton('edit_save'); // by default the button's item id is 'edit_save'.
saveButton.addClass('disabled');
// Enable save button after any edit action
$("input, select, textarea").on("change input", function() {
saveButton.removeClass('disabled');
});The following OnLoad Event JS code operates on modal popup Edit page and will not run in the standard Edit page. It warns of "unsaved changes" and provides a means to opt out, when the user clicks the Close button ('x') in the top right corner of the page. I was unable to get this warning to work on the 'Cancel' button, because that buttons onclick event runs too late in the page lifecycle - as it runs after the page closes. Xlinesoft provides a better means of warning of "unsaved changes" on their standard Edit page.
// If this is a popup, intercept close button click to check for unsaved changes and allow user to opt out of closing with
$('.modal-header .close').on('click', function(e) {
if (pageObj.isPageModified()) {
if (!confirm("You have unsaved changes. Are you sure you want to close?")) {
window.formChanged = false;
e.stopPropagation();
e.preventDefault();
return false;
}
}
});