Test for a dirty form (simulate enableModifiedFlag)

if (XSP._isDirty()){
	if (confirm ("Are you sure you want to navigate away from this page?" + "\n" + "\n" +
		"This document may contain unsaved changes." + "\n" + "\n" +
		"Press OK to continue, or Cancel to stay on the current page.")) {
		return true;
	} else {
		return false;
	}
} else {
	return true;
}





This emulates the server-side enableModifiedFlag property and the related modifiedMessage property available on XPages and custom controls.

The client-side JS checks if a form has been modified (is dirty) and if so, displays a confirm prompt that allows the user to decide to stay on the page or to navigate away from the page.

I got the code from this answer on Stack Overflow:
http://stackoverflow.com/a/10428881/785061

Note that the original code is licensed under cc-wiki with attribution required - see http://creativecommons.org/licenses/by-sa/3.0/.

JavaScript (Client)
Per Henrik Lausten
September 8, 2012 4:11 PM
Rating
118

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...