PDA

View Full Version : Ext.form.Labelable -> setFieldDefaults



tobiu
25 Aug 2015, 10:48 AM
hi guys,

when using the fieldDefaults config in a FormPanel, i noticed that listeners get ignored completely.

The reason is that the Ext.form.Labelable -> setFieldDefaults method only allows keys that are a config in this class. Although the class itself does fire an event, it does not have a config for listeners.

I think the following change is a good way to add listeners without colliding with listeners defined on the field itself:



setFieldDefaults : function(defaults) {
var me = this,
key;

for (key in defaults) {
if (!me.hasOwnProperty(key)) {
me[key] = defaults[key];
}
}

if (defaults && defaults.listeners) {
me.on(defaults.listeners);
}
}


It would be nice if you could add this, since overriding mixins cost performance for apps.

thx and best regards
tobi

Gary Schlosberg
27 Aug 2015, 5:00 PM
Thanks for the report. Can you please post a test case which reproduces this issue?https://fiddle.sencha.com/#home

tobiu
28 Aug 2015, 5:33 AM
hmm, thought that would be trivial since you can see there is no listerners config in the labelable file :)

try this:


Ext.application({
name : 'Fiddle',

launch : function() {
Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
fieldDefaults: {
listeners: {
blur: function() {
console.log('blur');
}
}
},
items: [
{
xtype: 'textfield'
}
]
});
}
});


and you will see no logs for the blur event.

in case you do add the override before it, it works:


Ext.define('Ext.overrides.form.Labelable', {
override : 'Ext.form.Labelable',

overrideContent : {
setFieldDefaults : function(defaults) {
var me = this,
key;

for (key in defaults) {
if (!me.hasOwnProperty(key)) {
me[key] = defaults[key];
}
}

if (defaults && defaults.listeners) {
me.on(defaults.listeners);
}
}
}

}, function () {
var me = this,
mixinId = me.prototype.mixinId;

Ext.Object.each(Ext.ClassManager.classes, function (name, cls) {
if (cls.prototype && cls.prototype.mixins && cls.prototype.mixins.hasOwnProperty(mixinId)) {
Ext.apply(cls.prototype, me.prototype.overrideContent);
}
}, me);
});


regarding: "It would be nice if you could add this, since overriding mixins cost performance for apps"

you will have to agree, when you look at the override callback.