1. #1
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Connecticut
    Posts
    661
    Answers
    8
    Vote Rating
    64
    blomasky is a jewel in the rough blomasky is a jewel in the rough blomasky is a jewel in the rough blomasky is a jewel in the rough

      0  

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

    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 - Architect Dev Team
    Join Date
    Jan 2009
    Location
    Frederick, Maryland
    Posts
    886
    Answers
    63
    Vote Rating
    32
    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
    661
    Answers
    8
    Vote Rating
    64
    blomasky is a jewel in the rough blomasky is a jewel in the rough blomasky is a jewel in the rough blomasky is a jewel in the rough

      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 - Architect Dev Team
    Join Date
    Jan 2009
    Location
    Frederick, Maryland
    Posts
    886
    Answers
    63
    Vote Rating
    32
    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,304
    Answers
    8
    Vote Rating
    106
    ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice

      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