dimanche 18 janvier 2015

HOW to override default listeners without defining a new object

Hi:

I have a bunch of Ext.form.field.Text which are instantiated via Ext.create and via the xtype widget 'textfield'.


I would like to override the focus and blur without needing to defining a new object and updating the code with the name of the new object.


I am playing around with the test code below:



Code:



Ext.override('Ext.form.field.Text',{
listeners: {
focus: function(field,ev, options){
console.log("AAAAAA");
},
blur: function(field,ev,options){
console.log("BBBBBB");
}
}
});


Ext.create('Ext.form.Panel', {
title: 'Contact Info',
width: 300,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Name',
allowBlank: false // requires a non-empty value
}, {
xtype: 'textfield',
name: 'email',
fieldLabel: 'Email Address',
vtype: 'email' // requires value to be a valid email address format
}]
});

I can get things working if I define a new object which extends the 'Ext.form.field.Text' and add the focus and blur listeners, but that's not i'm after.

Any help is appreciated.


Thanks

J.






HOW to override default listeners without defining a new object

Aucun commentaire:

Enregistrer un commentaire