View Full Version : set handler for all button of a toolbar

13 Oct 2010, 9:53 AM
i'm gettin crazy with this problem.

I have a toolbar with 3 buttons.
Now I need to set the handler for all of those buttons in the main class.

I get the toolbar object in this way:

this.northBbar = this.getComponent('northPanel').getBottomToolbar();

I can access to any button in this way:

this.northBbar.items.items[x] //x is the item id: 0,1,2

But I don't know how to set the handler of those button from here....


13 Oct 2010, 10:28 AM

13 Oct 2010, 10:34 AM
Tnx for the answer

setHandler apllyed to what? To every items? It is not what I'm searching for....
I need to set the handler of all the buttons together not one by one.


13 Oct 2010, 10:39 AM
duplicate post, next post is the correct one

13 Oct 2010, 10:41 AM
Off the top of my head (read: untested), in the toolbar's config, try setting the defaults config object, like

defaults :
handler : function(e)
// Handler code here
Ideally, that'll set the same handler code for each item. This will only affect buttons, AFAIK.

13 Oct 2010, 10:44 AM
Are you setting the them to the same handler?

13 Oct 2010, 10:45 AM
I assume because he said "I need to set the handler of all the buttons together not one by one." that he wants to set the handlers of the buttons to do/be the same thing...

13 Oct 2010, 10:57 AM
Yeah, that's why i asked :).

I imagine "together" could mean "in a loop" or by one utility method.

13 Oct 2010, 11:00 AM
Buttons have a setHandler method that you can call, e.g.

btn.setHandler(handler, scope);

14 Oct 2010, 2:44 AM
Hey i'm back :) tnx for the answers.
Yes i need to set the same handler for all the buttons.

That's because the function takes a parameter that has resulted from the button event.

Ok, I try and then I tell you, thanks