Detect if form has changed or \is dirty\"?"

  • 1 February 2019
  • 3 replies
  • 61 views

Badge +8

Is there anyway to detect if a Nintex form has changed?  This is sometimes called an IsDirty function.


3 replies

Badge +7

Maybe if you describe what you really want to achive we could help you more specific.

 

As to your question: no, there is no such property (exposed).

Badge +8

Hi,

 

No there is not out of the box functionality by Nintex to determine if the form is changed or not, but I worked around a similar scenario by capturing the field values (fields which I wanted to check if they have changed our not) during the form load and again before the form is saved i.e. in javascript. If the Old value != new value then do some action.

 

hth,

 

regards,

Shrini

Badge +1

4 years later no replies eh?

 

Here’s some code for auto saving that I used to save a non-new form.  This would live in the Custom Javascript (or an embedded js file) in the form settings.

window.isDirty will give you the check, events are hooked for key press and click on input/select fields.


/* CODE FOR AUTO SAVE 

Have the following UI Elements in place:
- A Yes/No control with JS Client Name = bProcessWorkflow
- The ProcessWorkflow field is to prevent workflow from doing background actions after an auto save.
- A Button with css class "btnAutoSave" and button action of "Save and Continue"
- A label with css class "lblAutoSaveTimer"

This code will:
- Detect keypresses or mouse clicks (on anything) (window.isDirty)
- Save the last time it was accessed (window.lasTouched)
- Click the auto save button (btnAutoSave) after 10 minutes (window.autoSaveMinutes)
- Check if the form is valid before performing a save action
- Check if the form is a new Form (window.isNewForm) and not perform auto save on new forms.
- Display a message indicating if the form will auto save and when (css class "lblAutoSaveTimer")
- Click a button after the auto-save check and validation check succeed (css class "btnAutoSave")

*/


function custom_markFormDirty() {window.isDirty=true;window.lastTouched=new Date();NWF$(".btnAutoSave").prop("disabled",null);};

function getMinutesSinceTouched() {return (((new Date() - window.lastTouched) / (1000*60)));};

function custom_checkAndAutoSaveIfDirtyFor10Min() {
  if(window.isNewForm) {
     NWF$(".lblAutoSaveTimer").text("Automatic saving is disabled for new forms.");
     return; /* Do nothing for new forms */
  }
  if(window.isDirty) {
     NWF$(".lblAutoSaveTimer").text("This form will automatically save in " + Math.round(window.autoSaveMinutes - window.getMinutesSinceTouched()).toString() + " min(s).");
  } else {
     NWF$(".lblAutoSaveTimer").text("");
  }

  var timeSinceTouched = window.getMinutesSinceTouched();
  if(window.isDirty && timeSinceTouched >= window.autoSaveMinutes) {  
    console.log("Autosaving...");
    ValidationSummaryOnSubmit(NWF$(".nf-validation-summary").prop("validationGroup"));
    var isValid = Page_ClientValidate();
    if (!isValid) {
       console.log("Autosaving cancelled, validation issues.");
       NWF$("#s4-workspace").scrollTop(0);  
       ValidationSummaryOnSubmit(NWF$(".nf-validation-summary").prop("validationGroup")); 

       /* Check later... */
       NWF$(".lblAutoSaveTimer").text("This form cannot be auto-saved if it is invalid.");
       setTimeout( custom_checkAndAutoSaveIfDirtyFor10Min,60000); /* 1min */
    } else {
       console.log("Autosaving... Form is valid...");
       NWF$(".lblAutoSaveTimer").text("This form is new being automatically saved...");
       NWF$('#'+bProcessWorkflow).prop('checked',false);
       NWF$(".btnAutoSave").click();
    }
  } else {
     /* check again later */
     setTimeout( custom_checkAndAutoSaveIfDirtyFor10Min,60000); /* 1min */
     console.log("Nothing to autosave.");
  }
};

NWF.FormFiller.Events.RegisterAfterReady(function(){

window.autoSaveMinutes = 10;
window.isNewForm = (getQueryVariable("ID") === false);
window.isDirty=false;
window.lastTouched=new Date();
NWF$(".btnAutoSave").prop("disabled","1");
NWF$(window).keypress(custom_markFormDirty);
NWF$("input").click(custom_markFormDirty);
NWF$("select").click(custom_markFormDirty);
NWF$(".nf-filler-control").click(custom_markFormDirty);
NWF$(window).click(custom_markFormDirty);
custom_checkAndAutoSaveIfDirtyFor10Min();
});
 

Reply