1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    18
    Vote Rating
    0
    DavorZ is on a distinguished road

      0  

    Question Multiple Ext.Button handlers

    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
    Sencha User johnathanhebert's Avatar
    Join Date
    Apr 2008
    Posts
    77
    Vote Rating
    0
    johnathanhebert is on a distinguished road

      0  

    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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,714
    Vote Rating
    438
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

  4. #4
    Sencha User
    Join Date
    Feb 2011
    Posts
    18
    Vote Rating
    0
    DavorZ is on a distinguished road

      0  

    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