2
votes

I have a Grid panel containing records which, on-click, will be loaded into a Form panel for editing.

On "close" of our form panel, we're calling myForm.getForm.reset(), which seems to reset the record but the values in the form fields themselves persist.

// Load record
me.down('form').loadRecord(record);
// Close
me.down('form').getForm().reset() or me.down('form').reset()

Please advise how to also clear values in the form upon resetting our record.

5

5 Answers

6
votes

Do you have trackResetOnLoad set to true for the form? If so, what you really want is it set to false.

3
votes

Maybe you need set 'resetRecord' parameter into 'reset()' method for unbind any record set by 'loadRecord' method.

Example:

me.down('form').getForm().reset(true)
2
votes

You can override the default form panel to add this functionality. Add the following to your code:

 Ext.override(Ext.form.Panel, {
     clearForm:function(){
         Ext.each(this.getForm().getFields().items, function(field){
                field.setValue('');
         });
     }
});

You can then clear a form using:

myForm.clearForm()

Where myForm is your form panel.

The reset() method just resets the form back to the last record loaded.

2
votes

If you want to maintain trackResetOnLoad=true (e.g. so you can use the form's "dirtychange" event) another approach is to take a copy of the values just after the form is created like var originalValues = myForm.getFieldValues(); then simply restore those values using myForm.setValues(originalValues); instead of calling myForm.reset(...);

-1
votes

You can try this...

this.up('form').getForm().reset();