PDA

View Full Version : [CLOSED] overridding Ext.form.Label seems not to work



mariuszk
4 Dec 2012, 2:08 AM
extjs 4.1.1 with firefox/chrom

ovverridden constructor or initComponent are not called



Ext.override(Ext.form.Label, {
constructor: function(cfg) {
console.log('i was here');
this.callOverridden(arguments);
},
initComponent: function() {
console.log('i was here too');
this.callOverridden(arguments);
}
});

evant
4 Dec 2012, 2:37 AM
Overrides should use Ext.define:



Ext.define('Foo', {
override: 'Ext.form.Label',
constructor: function(cfg) {
console.log('i was here');
this.callOverridden(arguments);
},
initComponent: function() {
console.log('i was here too');
this.callOverridden(arguments);
}
});

Ext.require('*');

Ext.onReady(function() {
new Ext.form.Label({
renderTo: document.body
});
});


Tested with the latest from source and I see both logs.

mariuszk
4 Dec 2012, 3:59 AM
Many thanks.

But "Ext.define" create new "class" and override extend the existing. So they are not same.

evant
4 Dec 2012, 12:07 PM
As it goes, if I run the same code (it's functionality equivalent) it works in the latest branch as well:



Ext.require('*');

Ext.onReady(function() {

Ext.override(Ext.form.Label, {
constructor: function(cfg) {
console.log('i was here');
this.callOverridden(arguments);
},
initComponent: function() {
console.log('i was here too');
this.callOverridden(arguments);
}
});

new Ext.form.Label();

});



The advantage of the define() syntax is it will work with dynamic loading.