Pages

Tuesday, February 14, 2012

How to disable change / validation events when using loadRecord

When you use Basic.loadRecord() to load a record into a form, all of the form fields fire their change events, which you might not want. Here's a quick way to fix this:

This prevents change events from firing, but then re-enables them:

var basic = form.getForm();

basic.getFields().each(function(item, index, length){
  item.suspendCheckChange++;
});

basic.loadRecord(myRecord);

basic.getFields().each(function(item, index, length){
  item.suspendCheckChange--;

}); 

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; 
});