Loading ...
Sorry, an error occurred while loading the content.

Splitbutton and events

Expand Messages
  • grotgrot
    I can t hook up events with the splitbutton. I want to get the main button being clicked (which according to the doc is an option event) as well as find out
    Message 1 of 4 , Mar 1 4:56 PM
    • 0 Attachment
      I can't hook up events with the splitbutton. I want to get the main
      button being clicked (which according to the doc is an "option" event)
      as well as find out which menu items are clicked on.

      addListener gives me Javascript errors (FF2, Firebug)

      this._events has no properties
      http://localhost:1234/js/yahoo/element-beta.js
      Line 576
      if (!this._events[type]) { // create on the fly


      That references code at the beginning of the addListener method.

      I can put a click handler in the constructor, but then it fires no
      matter where the click was including the drop down thingy.

      Additionally getting the menu just gives me null.

      The widget actually displays and interacts fine. But without events
      it is rather useless :-)

      var button=new YAHOO.widget.Button("query_button",
      { type: "splitbutton",
      menu: "query_button_menu"
      });

      // these cause error given above
      button.addListener("click", function(o) {console.log("click", o);});
      button.addListener("option", function(o) {console.log("option", o);});

      console.log(button.getMenu()); // returns null
    • Todd Kloots
      grotgrot - The click event for a split button only fires when the label/default region of the button is clicked. The option event fires when the split
      Message 2 of 4 , Mar 4 12:11 PM
      • 0 Attachment
        "grotgrot" -

        The "click" event for a split button only fires when the label/default region of the button is clicked. The "option" event fires when the split button's menu is invoked (when the user clicks on the split button's arrow). The "addListener" bug has been filed (https://sourceforge.net/tracker/index.php?func=detail&aid=1668511&group_id=165715&atid=836476) and will be fixed. In the meantime, here is an example how you can hook up all of your event listeners in the body of a "init" event handler:

        http://yuiblog.com/sandbox/yui/v220/examples/button/example03.php

        - Todd

        ----- Original Message ----
        From: grotgrot <grotgrot@...>
        To: ydn-javascript@yahoogroups.com
        Sent: Thursday, March 1, 2007 4:56:09 PM
        Subject: [ydn-javascript] Splitbutton and events

        I can't hook up events with the splitbutton. I want to get the main
        button being clicked (which according to the doc is an "option" event)
        as well as find out which menu items are clicked on.

        addListener gives me Javascript errors (FF2, Firebug)

        this._events has no properties
        http://localhost:1234/js/yahoo/element-beta.js
        Line 576
        if (!this._events[type]) { // create on the fly


        That references code at the beginning of the addListener method.

        I can put a click handler in the constructor, but then it fires no
        matter where the click was including the drop down thingy.

        Additionally getting the menu just gives me null.

        The widget actually displays and interacts fine. But without events
        it is rather useless :-)

        var button=new YAHOO.widget.Button("query_button",
        { type: "splitbutton",
        menu: "query_button_menu"
        });

        // these cause error given above
        button.addListener("click", function(o) {console.log("click", o);});
        button.addListener("option", function(o) {console.log("option", o);});

        console.log(button.getMenu()); // returns null







        Yahoo! Groups Links
      • grotgrot
        ... Great. I had assumed my code was bad :-) I switched to doing the event hookups in the oninit handler as you suggested and all works well. Thanks.
        Message 3 of 4 , Mar 6 4:57 PM
        • 0 Attachment
          --- In ydn-javascript@yahoogroups.com, Todd Kloots <kloots@...> wrote:
          > The "addListener" bug has been filed

          Great. I had assumed my code was bad :-)

          I switched to doing the event hookups in the oninit handler as you
          suggested and all works well.

          Thanks.
        • Willem Joosten
          ... Todd, In version 2.2.2 the init event is removed from Button. So the approach used in the example you give doesn t work anymore. Is there a new approach to
          Message 4 of 4 , May 10, 2007
          • 0 Attachment
            --- In ydn-javascript@yahoogroups.com, Todd Kloots <kloots@...> wrote:
            >
            > In the meantime, here is an example how you can hook up all of your
            > event listeners in the body of a "init" event handler:
            >
            > http://yuiblog.com/sandbox/yui/v220/examples/button/example03.php
            >

            Todd,

            In version 2.2.2 the init event is removed from Button. So the
            approach used in the example you give doesn't work anymore. Is there a
            new approach to add event listeners to the menu / menu items?

            I tried to the following (using a input and select in html):

            var button = new YAHOO.widget.Button('btnProjectSelector', { type:
            'menubutton', menu: 'projectMenu');
            YAHOO.util.Event.onContentReady('projectMenu', function(){
            initProjectMenu(); });

            The idea is that the menu initialisation in button is triggered by the
            same onContentReady event. So if events are fired in order they're
            created this should work.

            But initProjectMenu is never fired. When you switch the two lines it
            is fired so the code is ok. The problem is the removal of the original
            select item (line 1074 in button-beta.js)

            Regards,
            Willem
          Your message has been successfully submitted and would be delivered to recipients shortly.