PDA

View Full Version : new window addlistener



alberto01
11 Nov 2010, 1:30 AM
Hi,
I have this code:


genericWindowUi = Ext.extend(Ext.Window, {
title: 'My Window',
width: 400,
height: 250,
initComponent: function() {
this.buttons = [
{
text: 'Close',
id: 'close',
ref: 'close'
},{
text:'Submit',
id:'submit'
}];
genericWindowUi.superclass.initComponent.call(this);
}
});


genericWindow = Ext.extend(genericWindowUi, {
constructor: function(items) {
this.items = items;
genericWindow.superclass.constructor.call(this);
},
initComponent: function() {
genericWindow.superclass.initComponent.call(this);
}

});
Ext.reg('genericWindow', genericWindow);
/********************************/

win = new genericWindow([{xtype: 'myPanel'}]);



I want to add an handler to the buttons... But when I try to get them I get an error.



win.getComponent('close').addListener('click', function(){ alert ('ok')});


Uncaught TypeError: Cannot call method 'addListener' of undefined

why?


tnx

steffenk
11 Nov 2010, 3:04 AM
buttons already have a clickhandler, just use
handler: function() {}
in button config

alberto01
11 Nov 2010, 3:07 AM
Tnx, but i need to se the handler from the opener... not directly inside the window...

steffenk
11 Nov 2010, 3:26 AM
ref is wrong, should be ../close
getComponent is used with itemId/ref, not id - remove id

win.getComponent('close').handler = function() {...}