Reset Form Record Not Clearing Values - ExtJS 4.2
Asked Answered
B

5

2

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.

Bellhop answered 24/9, 2013 at 17:58 Comment(0)
L
6

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

Lemkul answered 24/9, 2013 at 19:14 Comment(2)
trackResetOnLoad: false .. changed from trackResetOnLoad: true .. worked!Helprin
If you set trackResetOnLoad to false the dirtychange event isn't fired. Consider one of the other solutions if you need that to work.Gratify
S
3

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

Example:

me.down('form').getForm().reset(true)
Suprarenal answered 25/9, 2013 at 3:38 Comment(0)
I
2

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.

Inositol answered 30/10, 2013 at 11:55 Comment(2)
This is not the same as resetting the form (at least in the way the OP wants to). By setting all the fields to null, if the user saves the form, the previous record will update to have null values. Reimius's answer is correct.Trinh
@Lemkul - likely because it represented a correct answer to those who voted. Answers can prove meritorious for a variety of reasons, and can both be voted on in terms of validity, benefit and opinion- indeed see Glenn Lawrence's commentInositol
G
2

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(...);

Gratify answered 27/3, 2015 at 21:54 Comment(0)
R
-1

You can try this...

this.up('form').getForm().reset();
Rimini answered 9/7, 2014 at 13:50 Comment(1)
Why such a CUBITAL text?Transfiguration

© 2022 - 2024 — McMap. All rights reserved.