Pages

Tuesday, February 14, 2012

How to prompt the user to save a dirty form if leaving the page

How to prompt the user to save a dirty form if leaving the page:

  1. set the Basic Form's trackResetOnLoad to true
  2. handle the form's dirtychange event

something like this:

function my_onbeforeunload(e){
  message = 'You have unsaved changes. Are you sure you want to leave this page?'; 
  e = e || window.event;
  if(e){
    e.returnValue = message;
  }
  return message;
}

form.on('dirtychange', function(basic, dirty, eOpts){
  window.onbeforeunload = dirty ? my_onbeforeunload : null; 
});

No comments:

Post a Comment