PDA

View Full Version : 'keyup' listener fires on form/page load



caleywoods
26 Apr 2012, 8:33 AM
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:



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):


function validateSearchInput() {
console.log('fired');
}

mitchellsimoens
27 Apr 2012, 6:38 AM
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.