Idea
Discussion

Add parameter into crt.ClosePageRequest to prevent popup for unsaved data

When adding code into a page that has to call crt.ClosePageRequest to close the page in the code, it's a very common pattern to want to close the page without the standard dialog prompt to the user asking about unsaved changes appearing. It is possible to override the crt.CanDiscardUnsavedDataRequest handler to return true to do so, but most of the time you don't want this to happen for any close page event, just the one in your particular code path(s). This leads to somewhat over-complicated code to set an attribute so that the crt.CanDiscardUnsavedDataRequest handler can know if you've gone down this code path where it can be discarded or it's from some other source such as the user clicking to close the page, introducing possible bugs.

 

I would propose that it should be possible to pass in a parameter to the crt.ClosePageRequest call to specifically tell that handler whether it should discard the unsaved changes or not, defaulted to false so that current behaviour is maintained. This would look something like this in my view:

{
	"request": "usr.SomeHandler",
	"handler": async (request, next) => {
		// Some logic which decides that the page should be closed without saving
		
		// Close the page without prompting the user
		request.$context.executeRequest({
			type: "crt.ClosePageRequest",
			$context: request.$context,
			canDiscardUnsavedData: true
		});
		


		return next.handle(request);
	}
}

 

This is a lot more natural and clear what is happening, as all the logic is contained within the single handler's logic, and so doesn't require jumping to different handlers (which aren't obvious from just looking at the handler in question's code in the current ways of doing this) and unpicking that the code is preventing that popup elsewhere.

0 comments
Show all comments