1. #1
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Connecticut
    Posts
    961
    Vote Rating
    282
    Answers
    12
    blomasky has much to be proud of blomasky has much to be proud of blomasky has much to be proud of blomasky has much to be proud of blomasky has much to be proud of blomasky has much to be proud of blomasky has much to be proud of blomasky has much to be proud of blomasky has much to be proud of

      0  

    Default Answered: Can I have more than one action point to the same function?

    Many times I have multiple buttons (i.e. add 10%, add 20%) that I want to call the same function (action) and let the function determine what to do by the component passed. It seems that an action in SA3 has to be unique to one control query. Am I missing something?

    The way I am handling this now, is to add the 2nd (and any additional) events in the "init" function.

    Is there a better way?

    Thanks
    Bruce

  2. Quote Originally Posted by blomasky View Post
    The problem is, that an action requires a "UNIQUE" name for each function. I didn't know is there is a trick to re-use one, besides just having a listener in the INIT function...
    I understand your issue... I was just giving a work-around for the limitation.

  3. #2
    Sencha User
    Join Date
    Jan 2009
    Location
    Frederick, Maryland
    Posts
    925
    Vote Rating
    33
    Answers
    66
    jminnick has a spectacular aura about jminnick has a spectacular aura about

      0  

    Default

    Quote Originally Posted by blomasky View Post
    Many times I have multiple buttons (i.e. add 10%, add 20%) that I want to call the same function (action) and let the function determine what to do by the component passed. It seems that an action in SA3 has to be unique to one control query. Am I missing something?

    The way I am handling this now, is to add the 2nd (and any additional) events in the "init" function.

    Is there a better way?

    Thanks
    Bruce

    Maybe create a global function that all the unique functions can call?

    Code:
    function handleAllButtons(btn) {
    }
    
    btnTap1: function(button, e, eOpts) {
        handleAllButtons(btn);
    }
    
    btnTap2: function(button, e, eOpts) {
        handleAllButtons(btn);
    }
    
    btnTap3: function(button, e, eOpts) {
        handleAllButtons(btn);
    }
    Jason Minnick
    Sencha Architect Development Team

  4. #3
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Connecticut
    Posts
    961
    Vote Rating
    282
    Answers
    12
    blomasky has much to be proud of blomasky has much to be proud of blomasky has much to be proud of blomasky has much to be proud of blomasky has much to be proud of blomasky has much to be proud of blomasky has much to be proud of blomasky has much to be proud of blomasky has much to be proud of

      0  

    Default

    The problem is, that an action requires a "UNIQUE" name for each function. I didn't know is there is a trick to re-use one, besides just having a listener in the INIT function...

  5. #4
    Sencha User
    Join Date
    Jan 2009
    Location
    Frederick, Maryland
    Posts
    925
    Vote Rating
    33
    Answers
    66
    jminnick has a spectacular aura about jminnick has a spectacular aura about

      0  

    Default

    Quote Originally Posted by blomasky View Post
    The problem is, that an action requires a "UNIQUE" name for each function. I didn't know is there is a trick to re-use one, besides just having a listener in the INIT function...
    I understand your issue... I was just giving a work-around for the limitation.
    Jason Minnick
    Sencha Architect Development Team

  6. #5
    Sencha Premium Member
    Join Date
    May 2010
    Location
    Guatemala, Central America
    Posts
    1,414
    Vote Rating
    302
    Answers
    10
    ssamayoa is an unknown quantity at this point

      0  

    Default

    Quote Originally Posted by blomasky View Post
    Many times I have multiple buttons (i.e. add 10%, add 20%) that I want to call the same function (action) and let the function determine what to do by the component passed. It seems that an action in SA3 has to be unique to one control query. Am I missing something?

    The way I am handling this now, is to add the 2nd (and any additional) events in the "init" function.

    Is there a better way?
    With custom attribute and use it in the selector?
    Code:
    {
        xtype: "button",
        text: "Up 20%",
        _action: "up20"
    }...
    Then:
    Code:
    this.control({
        "mypanel button [_action=up20]":
            click: this.someMethod
        }
        ...
    )
    UI: Sencha Architect 3.x / ExtJS 4 & 5
    Server side: JEE / EJB 3.x / CDI / JPA 2.x/ JAX-RS / JasperReports
    Application Server: Glassfish / WildFly
    Databases: Oracle / DB2 / MySQL / Firebird

    If you like my answer please vote!

Thread Participants: 2