PDA

View Full Version : [OPEN][PR3] Ext.form.Field and Ext.form.Basic are missing 'reset' and 'beforereset'



jlmorgan
10 Mar 2011, 8:10 AM
Situation where this missing event becomes difficult to deal with:

Form containing Country and State ComboBox where State is dependent on Country. If your State ComboBox changes the available values based on the Country selected, then loading data from a record, while potentially resolved via filters, resetting the form poses an issue in retrieving the previous filter and providing the correct data to reset.

For example,

1) Form is rendered with empty fields and no data loaded into the State ComboBox
2) record.data = { country_id: '1', state_id: '100' }
3) state.store.filter('country_id', record.get('country_id'));
4) state.store.load(); // Data now loaded with states filtered for the country_id passed.

// Set appropriate hook to ensure data is loaded before attempting to set it, such as state.store.on('load'), etc.

5) form.loadRecord(record);
6) Country sets displayValue associated to country_id: 1
7) State sets displayValue associated to country_id 1, state_id: 100
8) Select a different Country (country_id = 2)
9) State reloads states filtered with country_id: 2
10) form.getForm().reset() // User resets the form
11) Country field resets correctly
12) State field fails to reset properly since the filter used initially is lost.

While I do not expend the managing of dependencies to be handled by Ext, being able to access Ext.form.Basic and Ext.form.Field events for beforereset and reset would be extremely useful in managing issues relating to the aforementioned example.

Possible solutions:

Ext.form.Basic


reset: function() {
if (this.fireEvent('beforereset') !== false) {
this.getFields().each(function(f) {
f.reset();
});
this.fireEvent('reset');
}
return this;
},


Ext.form.Field


reset: function() {
var me = this,
curVal = this.getValue(),
origVal = this.originalValue;

if (this.fireEvent('beforereset', me, origVal, curVal) !== false) {
this.setValue(this.originalValue);
this.clearInvalid();
this.wasValid = true;
this.fireEvent('reset', me, origVal, curVal);
}
},