0

I am using liferay 6.2. I have an add button beside a select box. Upon selecting an element from the box and clickin on add should add the respective element. It was working well on liferay 6.1 but now the click event does not do anything instead jumps to a new window. My code is here:

    AUI.use(
    'aui-button',
    function(A) {
        new A.Button(
                {
                    handler : function() {
                        // do some processing
                    },

                    icon : 'plus',
                    label:'Add',
                    render : '#newcategorybutton'
                });
    });

I also tried to use:

    YUI().use(
      'aui-button',
      function(Y) {
    var addButton=  new Y.Button(
          {
            label: 'Add',
            srcNode: '#newcategorybutton'
          }
        ).render();
       addButton.addListener("click",handleClick);
       function handleClick()
        {
           alert("clicked");
        }
      }
    );

BUt it did not work. Does anybody have some idea regarding this?

user596502
  • 417
  • 3
  • 10
  • 22
  • 1
    use "on" to register the click listener. Some [documentation](http://yuilibrary.com/yui/docs/event/). If the button is part of a form you'll want to set the `type` to `button` to prevent unwanted form submissions. – Origineil Aug 07 '14 at 13:56

1 Answers1

1

As @Origineil said, you need to use the on method to add an event listener.

myButton.on(
    'click'
    function(event) {
        // do stuff
    }
);

You can also do it in the config.

var myButton = new A.Button({
    // config stuff,
    on: {
        'click': function(event) {
            // do stuff
        }
    }
});
Byran Zaugg
  • 967
  • 9
  • 25