Results 1 to 4 of 4

Thread: Multiple Ext.Button handlers

  1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    21

    Question Multiple Ext.Button handlers

    is there a way to put multiple handlers on a button, so it starts multiple functions at once??
    something like, open all button??

    Code:
    Ext.onReady(function() {
    
        var myButtonAll = new Ext.Button({
    
            text       : "OPEN ALL",
            handler    : varname, varname...???
            renderTo   : "buttons",
            scale      : "large",
            iconCls    : "button_two",
            width      : 100,
            height     : 100,
     
        
        });
            
    
    });

  2. #2

    Default

    Since the "handler" config option just assigns the function to the click event of the button... you can add multiple click events to your button like this:

    Code:
    Ext.onReady(function() {
        var myButtonAll = new Ext.Button({
            text       : "OPEN ALL",
            handler    : varname, varname...???
            renderTo   : "buttons",
            scale      : "large",
            iconCls    : "button_two",
            width      : 100,
            height     : 100,
        });
        myButtonAll.on('click', handler1);
        myButtonAll.on('click', handler2);
        myButtonAll.on('click', handler3);
        myButtonAll.on('click', handler4);
    });
    Or you can wrap all of them in an anonymous function like this:

    Code:
    Ext.onReady(function() {
        var myButtonAll = new Ext.Button({
            text       : "OPEN ALL",
            handler    : function() {
                            handler1.apply(this, arguments);
                            handler2.apply(this, arguments);
                            handler3.apply(this, arguments);
                            handler4.apply(this, arguments);
                        }
            renderTo   : "buttons",
            scale      : "large",
            iconCls    : "button_two",
            width      : 100,
            height     : 100,
        });
    });
    And the handlers should have the signature of the button click handler, for example:

    Code:
    handler1 = function(button, event) {...}
    Johnathan Hebert

  3. #3
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379

    Default

    You don't need to be an anonymous function. Adding multiple event listeners will affect performance. Best way to do it is have a wrapping function.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  4. #4
    Sencha User
    Join Date
    Feb 2011
    Posts
    21

    Default

    thank you very much, i did the wrapping , it works!!!

Similar Threads

  1. Ext.form.SliderField with multiple handlers?
    By apopescu in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 9 Apr 2010, 9:24 AM
  2. Multiple event handlers that modifies the same value
    By dolittle in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 3 Nov 2008, 8:34 AM
  3. Multiple Handlers
    By say2paul in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 24 Jan 2008, 11:52 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •