mcurrey
11 Nov 2008, 4:43 PM
I don't have the privileges to post to the premium forum, but I encountered the same problem as many others, mentioned here:
http://extjs.com/forum/showthread.php?t=39871
That is, the ComboBox 'change' event would be more useful in many situations if it fired as soon as the value in the ComboBox changes, instead of not until the ComboBox is blurred.
It's also not clear if the User Extensions site above is official, or what the process is, or if everything here has been moved there. Unfortunately I don't have time to read through a 13 page thread to determine that, but thought this would be helpful to folks. Anyone can feel free to post this uber-simple extension there, if appropriate.
The following extension to ComboBox fires the "change" event immediately after the "select" event, if the value has changed. No need to blur the field.
/**
* @class Ext.ux.BetterComboBox
* @extends Ext.form.ComboBox
* Fires "change" event at time of actual change, instead of just before/during blur
* @author mcurrey
*/
Ext.ux.BetterComboBox = Ext.extend(Ext.form.ComboBox, {
initComponent : function(){
Ext.ux.BetterComboBox.superclass.initComponent.call(this);
},
initEvents : function(){
Ext.ux.BetterComboBox.superclass.initEvents.call(this);
this.on('select', this.onBetterSelect, this);
},
// named this way to not interfere with Ext.form.ComboBox.onSelect()
onBetterSelect : function(record, index){
var v = this.getValue();
if(String(v) !== String(this.startValue)){
this.fireEvent('change', this, v, this.startValue);
}
}
});
Ext.reg('bettercombo', Ext.ux.BetterComboBox);
http://extjs.com/forum/showthread.php?t=39871
That is, the ComboBox 'change' event would be more useful in many situations if it fired as soon as the value in the ComboBox changes, instead of not until the ComboBox is blurred.
It's also not clear if the User Extensions site above is official, or what the process is, or if everything here has been moved there. Unfortunately I don't have time to read through a 13 page thread to determine that, but thought this would be helpful to folks. Anyone can feel free to post this uber-simple extension there, if appropriate.
The following extension to ComboBox fires the "change" event immediately after the "select" event, if the value has changed. No need to blur the field.
/**
* @class Ext.ux.BetterComboBox
* @extends Ext.form.ComboBox
* Fires "change" event at time of actual change, instead of just before/during blur
* @author mcurrey
*/
Ext.ux.BetterComboBox = Ext.extend(Ext.form.ComboBox, {
initComponent : function(){
Ext.ux.BetterComboBox.superclass.initComponent.call(this);
},
initEvents : function(){
Ext.ux.BetterComboBox.superclass.initEvents.call(this);
this.on('select', this.onBetterSelect, this);
},
// named this way to not interfere with Ext.form.ComboBox.onSelect()
onBetterSelect : function(record, index){
var v = this.getValue();
if(String(v) !== String(this.startValue)){
this.fireEvent('change', this, v, this.startValue);
}
}
});
Ext.reg('bettercombo', Ext.ux.BetterComboBox);