Reset Form Record Not Clearing Values - ExtJS 4.2

随声附和 提交于 2019-12-24 03:55:09

问题


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.


回答1:


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




回答2:


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

Example:

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



回答3:


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.




回答4:


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




回答5:


You can try this...

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


来源:https://stackoverflow.com/questions/18988727/reset-form-record-not-clearing-values-extjs-4-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!