View Full Version : Question re:Ext.Panel.addButton() parameter list

15 Jul 2009, 8:19 AM
The examples I've found for Ext.Panel's addButton method only pass the first parameter (the button object or definition for a button). When I try to use the other two parameters to set the handler and the scope, I can't get it to work.

Within the code defining the main panel I have:

var btnOk = new Ext.Button({
text: OpenLayers.i18n("Bookmarks.Ok.Button")
this.addButton(btnOk, myOnClickOk, this);
And I have a definition for myOnClickOk, but it never gets called:

myOnClickOk: function(){
At runtime, it gets to the point in the Ext.Button's onClick method where it checks for the existence of a handler and, using a debugger, I find there isn't one associated with the button.

During initialization of the panel, within the Ext.Panel addButton method, it seems to try to set this information with the passed parameters but then they get lost when the new Button is created by the method. The new button (that is actually added to the panel) has no handler associated to it.

Now, similar to the examples I've found, I can get it to work if I define it as follows:

var btnOk = new Ext.Button({
text: OpenLayers.i18n("Bookmarks.Ok.Button")
,handler: myOnClickOk
,scope: this
but I'm wondering if anyone's ever gotten it to work the other way and I'm just missing something or if there is actually a different problem that needs to be addressed.

I should note that I am currently using ExtJs 2.2 and this may have been addressed in a later version. At the moment, I am not able to upgrade to check.