1. #1
    Ext User
    Join Date
    Jul 2010
    Posts
    37
    Vote Rating
    0
    robertj98 is on a distinguished road

      0  

    Default Toolbar button handler question

    Toolbar button handler question


    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

  2. #2
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    9
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    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.

  3. #3
    Ext User
    Join Date
    Jul 2010
    Posts
    37
    Vote Rating
    0
    robertj98 is on a distinguished road

      0  

    Default


    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

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    9
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    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.

  5. #5
    Ext User
    Join Date
    Jul 2010
    Posts
    37
    Vote Rating
    0
    robertj98 is on a distinguished road

      0  

    Default


    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.

Similar Threads

  1. How to unregister a toolbar button handler
    By tBSTAR in forum Ext 3.x: Help & Discussion
    Replies: 4
    Last Post: 30 Dec 2009, 6:43 AM
  2. Get a grid in toolbar button event handler
    By xplicit in forum Ext 2.x: Help & Discussion
    Replies: 8
    Last Post: 9 Aug 2008, 4:14 PM
  3. Having trouble attaching a handler to a toolbar button
    By weyus in forum Ext 2.x: Help & Discussion
    Replies: 13
    Last Post: 17 Jul 2008, 2:30 PM
  4. Question about handler and listeners for a toolbar button
    By dddu88 in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 14 Mar 2008, 6:33 AM

Thread Participants: 1