1. #1
    Sencha User
    Join Date
    May 2012
    Posts
    6
    Vote Rating
    0
    MarwanT is on a distinguished road

      0  

    Default Answered: Listeners only work once

    Answered: Listeners only work once


    i am having a problem with my application , suppose there is a listener on a button in a certain panel , the listener works fine and the event gets fired in the first time. However , if i revisit this page the listeners wont work.i configure the listener in my controller as follows:
    Code:
    config: { 
     refs:{     
        btn : '#mybtn'     
      }  
    control : 
    {      
        btn : 
    {          
           tap : 'doSmth'   
                }    
            }  
          },  
    doSmth : function () { 
          //some code goes here
      }

  2. This is because refs don't like the id config. If you move away from using the id config you will find more success.

    Say you have this button config:

    Code:
    {
        text : 'Save User',
        id   : 'saveUser'
    }
    You will have the issue you are experiencing. But if you do something like this:

    Code:
    {
        text   : 'Save User',
        action : 'saveUser'
    }
    and have your ref use this selector instead of #saveUser:

    Code:
    'button[action=saveUser]'

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,811
    Answers
    3467
    Vote Rating
    834
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      1  

    Default


    This is because refs don't like the id config. If you move away from using the id config you will find more success.

    Say you have this button config:

    Code:
    {
        text : 'Save User',
        id   : 'saveUser'
    }
    You will have the issue you are experiencing. But if you do something like this:

    Code:
    {
        text   : 'Save User',
        action : 'saveUser'
    }
    and have your ref use this selector instead of #saveUser:

    Code:
    'button[action=saveUser]'
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

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

  4. #3
    Sencha User =NR='s Avatar
    Join Date
    Mar 2013
    Location
    Singapore
    Posts
    102
    Answers
    2
    Vote Rating
    -1
    =NR= has a little shameless behaviour in the past

      1  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    This is because refs don't like the id config. If you move away from using the id config you will find more success.

    Say you have this button config:

    Code:
    {
        text : 'Save User',
        id   : 'saveUser'
    }
    You will have the issue you are experiencing. But if you do something like this:

    Code:
    {
        text   : 'Save User',
        action : 'saveUser'
    }
    and have your ref use this selector instead of #saveUser:

    Code:
    'button[action=saveUser]'
    mitchell you one awesome person!!!
    it solved my problem also..

    the only thing is that i think this info can be a lot more helpfull if put on the documentation (especially on the intro section and the tutorial video which tell us on how to connect component to event on controller)

    **how do you know about this?

  5. #4
    Sencha User lstolz's Avatar
    Join Date
    May 2013
    Posts
    18
    Answers
    1
    Vote Rating
    3
    lstolz is on a distinguished road

      0  

    Default


    Thanks for this solution by mitchellsimoens.
    It works fine, is it possible to set the status of this thread to 'answered' so everybody searching for such a solution can see that this is the correct answer?

    Best
    Lennart