PDA

View Full Version : Override one Event (specialkey here)



Sergeith
20 Jun 2011, 5:45 AM
Hi,

Is it possible to override just one Event ?

I try this :



Ext.override(Ext.form.Field, {
listeners:{
specialkey:function(field,e) {
if (e.getKey() == e.ENTER) {
field.fireEvent('blur');
}
}
}
});but when i redeclare a field :



var MyTextField = new Ext.form.TextField({
width: 365,
enableKeyEvents: true,
listeners: {
focus: function() {
alert('focus');
},
keyup: function() {
alert('keyup');
},
blur: function() {
alert('blur');
}
},
hideLabel: true,
maxLength: 100
});my first listeners with 'specialkey', was overwritten

any solution ?

(sorry for my bad english)

Uberdude
20 Jun 2011, 8:39 AM
Rather than using Ext.override to specify a default listeners property for all Fields (which then gets overwritten, not merged, when you specify listeners on an instance), how about using observeClass:

Ext.util.Observable.observeClass(Ext.form.Field);
Ext.form.Field.on('specialkey', function(field,e) {
if (e.getKey() == e.ENTER) {
field.fireEvent('blur', field); // NB make sure to pass field as argument, to correctly recreate blur event
}
});

Sergeith
20 Jun 2011, 11:05 PM
Thx Uberdude, it works :)

I did not knew this method but it's very good ! (and better than my override!)