PDA

View Full Version : Toolbar button handler question



robertj98
6 Jul 2010, 1:22 AM
Hi,

I have just modified the JSONP example to try and display different content when I click on some test buttons in a toolbar.
However, the handler events for the toolbar seem to be firing when the page loads and then do not fire when you click on the buttons. The panel definition is:

new Ext.Panel({
fullscreen: true,
id: 'content',
scroll: 'vertical',
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: [
{
text: 'Refresh Issues',
handler: getIssues (1991)
},
{
text: '1978',
handler: getIssues (1978)
}
]
},{
id: 'status',
xtype: 'toolbar',
dock: 'bottom',
title: "Tap one of the buttons above."
}
]
})

The getIssues function is declared above this - I have an alert in it and it displays the data and year parameters, 1991 and 1978 when the page loads.

Am I doing something wrong here?

Robert Jones

TommyMaintz
6 Jul 2010, 10:26 AM
You are actually calling the handler methods (by adding the parentheses). Try just using getIssues, and then based on the button that is clicked you decide the year.

robertj98
6 Jul 2010, 10:37 AM
Thanks - I can see what what was happening now and the page is working OK. I called 2 different functions which displayed the years.
Where would you test for the button that was pressed? Is there a last event property or something that could be examined?

Robert Jones

TommyMaintz
6 Jul 2010, 1:36 PM
The btn is passed to the handler as the first argument. Also the default scope references the button, so inside your handler 'this' should point to the button that was pressed.

robertj98
7 Jul 2010, 1:05 AM
Thanks again.

Got it - used the parameter to get the buttons properties - using btn.getText() and called methods like btn.disable() - also added custom property to the button config definition ('pyear') and accessed this as btn.pyear within the handler function.

It is much clearer now.