PDA

View Full Version : Listeners defaults aren't merged automatically



llamerr
2 Jun 2016, 5:57 AM
There's already this thread https://www.sencha.com/forum/showthread.php?103275-Add-listeners-to-preconfigured-class&p=484276#post484276

My question is - why listeners from defaults still (after 5-6years) aren't merged automatically with other listeners?



xtype: 'form',
defaults: {
listeners: {
specialkey: function( field, e ) {
if ( e.getKey() == e.ENTER && field.isValid() && !me.queryById('acceptBtn').disabled ) {
me.fireEvent('accept');
me.close();
}
}
}
},

items: [
....
{
xtype: 'textfield',
listeners: {
change: function( field ) {

...

llamerr
2 Jun 2016, 6:15 AM
I solved it like this




var defaultListeners = {
specialkey: function( field, e ) {
if ( e.getKey() == e.ENTER && field.isValid() && !me.queryById('acceptBtn').disabled ) {
me.fireEvent('accept');
me.close();
}
}
};

...

xtype: 'form',
defaults: {
listeners: defaultListeners
},
items: [
...
{
xtype: 'textfield',
listeners: Ext.applyIf({
change: function( field ) {}
}, defaultListeners)
...


but my question stands - why apply ugly hacks and workarounds if it can be solved at the core of the problem instead?