Created
April 9, 2021 13:32
-
-
Save hhudson/c2d57dcbdbbc7e01021aada718fe4506 to your computer and use it in GitHub Desktop.
Javascript to enhance the 'Warn on Unsaved Changes' UX with item-level call-outs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//window.onbeforeunload = confirmExit; | |
/* The below will not run unless the above is uncommented. | |
* The recommendation is to run the above command in a | |
* dynamic action on page load of Page 0 with the Server | |
* Side Condition of 'Rows returned' for the following query: | |
* select 1 | |
* from apex_application_pages | |
* where application_id = :APP_ID | |
* and page_id = :APP_PAGE_ID | |
* and warn_on_unsaved_changes = 'Yes' | |
* This will have the result that the warning will respect the page | |
* level attribute setting for 'Warn on Unsaved Changes' | |
*/ | |
function warnOnItemLevel() { | |
var errors = []; | |
allItems = apex.page.forEachPageItem; | |
allItems( | |
$("#wwvFlowForm"), | |
function (el, name) { | |
if ( | |
apex.item(name).isChanged() && | |
!apex.item(name).element[0].classList.value.includes("js-ignoreChange") | |
) { | |
errors.push({ | |
message: "This item has unsaved changes", //consider using a substitution | |
location: "inline", | |
pageItem: name, | |
}); | |
} | |
}, | |
true | |
); | |
apex.message.clearErrors(); | |
apex.message.showErrors(errors); | |
} | |
function confirmExit() { | |
var pageRequest = "request" + $v("pRequest"); | |
if (apex.page.isChanged() && pageRequest == "request") { | |
warnOnItemLevel(); | |
pageRequest = null; | |
return ""; //will not actually be shown | |
} else { | |
pageRequest = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment