Tuesday, August 14, 2012

EXTJs clearing dirty flags for Form Fields

While working on some requirements, there was a need where in for a form when some values were entered, after taking some actions the entered values of the form were now suppose to be treated as the default values and not the changed values. In-short their dirty flags need to be cleared. (When ever we change a form field its dirty flag is set indicating that is has been modified.)

In order to clear the dirty flags of the fields we need to set the trackResetOnLoad=true for the formPanel.
The form Panel does not have such a config and we need to extend it in order to set this field:

        constructor : function(config) {
                config = config || {};
                config.trackResetOnLoad = true;
                this.callParent([config]);
        },


After this wherever we want to clear the dirty flags of the fields, we would need to use:

     //to clear the dirty flag
     var baseForm=this.getForm();
     baseForm.setValues(baseForm.getValues());

:).. Finally solved!!...

8 comments: