Results 1 to 2 of 2

Thread: 'keyup' listener fires on form/page load

  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    25
    Answers
    2
    Vote Rating
    4
      0  

    Default 'keyup' listener fires on form/page load

    I have a textfield that has a keyup listener that runs a function I've defined called validateSearchInput().

    Inside this function I'm setting a few variables up using Ext.getCmp('fieldid'); I know Ext.getCmp() isn't the best way to attack it and I'll worry about refactoring that as soon as I get this issue fixed.

    The issue is that the function is being fired when the form loads. I changed the function to just console.log('fired validateSearchInput!') and when you come to the form before you give focus to any element or press any keys you see the log output in the console.

    Below is how I have the listener setup:

    Code:
    listeners: {
        keyup: {
            fn: validateSearchInput()
        }
    }
    And here is what my simple validateSearchInput() function looks like now that is defined near the top of my file (before the Ext.onReady() event):
    Code:
    function validateSearchInput() {
        console.log('fired');
    }

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,381
    Answers
    3997
    Vote Rating
    1536
      0  

    Default

    The reason is because your code is executing the validateSearchInput method because you have '()' at the end of the function. Remove it and it will work as you expect it to.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

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

Posting Permissions

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