PDA

View Full Version : Ext js override init component function



mirkotus
24 Apr 2014, 4:44 AM
I am trying to override some code in the initComponent function of the Ext.window.MessageBox class. But none of the things that I change get applied. What is the problem here? Am I missing something?
Ext.define('hds.override.MessageBox', { override: 'Ext.window.MessageBox', initComponent: function() { console.log("init component 1"); //not reached this.callParent(); console.log("init component 2"); //not reached } });

mitchellsimoens
29 Apr 2014, 4:54 AM
Are you using Ext.Msg or the like to show the messagebox expecting your override to be hit?

gkohen
3 May 2014, 3:36 PM
@mirkotus, by the time you what to override the singltons Ext.Msg or Ext.MessageBox their are already constructed and initialized. You're best bet is to either override Ext.window.MessageBox, create and show it or extend the class and use that. To rephrase your snippet:

Ext.define('hds.override.MessageBox', {
override: 'Ext.window.MessageBox',
initComponent: function() {
console.log("init component 1"); //reached
this.callParent(arguments); // here you might have your own init and maybe callSuper instead
console.log("init component 2"); // reached
}});


Ext.application({
name: 'Fiddle',


launch: function() {


Ext.create('Ext.window.MessageBox').show({
title: 'Save Changes?',
multiline: true,
value: 'This is a very very very very very very very very very very very very very very very very very very long test',
msg: 'You are closing a tab that has unsaved changes.<br>Would you like to save your changes?',
buttons: Ext.Msg.YESNOCANCEL,
icon: Ext.Msg.ERROR
});
}
});