Warning that data will be lost if leaving the Web Entry form

From pmusers
Jump to: navigation, search

If a user leaves a Web Entry form or reloads the web page, any data entered by the user will be lost. It is good idea to warn users before leaving the Web Entry page that their work will be lost. JavaScript code can be added to the Web Entry's Dynaform that will display a generic warning message that the data will be lost before unloading the page and offer the user the change to stay on the page.

Add the following JavaScript code to the Dynaform:

window.onbeforeunload = function() {
  //remove the spinning circles that signify that the page is loading or submitting:
  var spinner = $(".spinner-icon");
  if (spinner.length) {
  //modern web browsers will show generic message instead of the custom message
  return "Are you sure that you want to leave and lose any data entered in this form?";

This code, which executes when the page is unloaded, hides the spinning circles that are displayed when a Dynaform is submitted. In older web browsers, returning a string would display a custom message to users, but modern web browsers display a generic warning message, like this one in Firefox:


or this message in Chrome: