View Full Version : the first argument of the click handler is undefined

4 Nov 2010, 9:48 AM
I instanciate a button with a click handler

var newButton = new Ext.Button({
id: decomp[i]+i,
text: decomp[i],
toggleGroup: 'role',
listeners: {
click: function(button, evt) {
console.log('ca passe');
currentRole = button.getText().trim();

When I explicitely fire the event "click" I get a javascript error saying that button ( the first argument) is undefined

What error could it be ?

Thank you in advance for your answers

4 Nov 2010, 10:14 AM
How are you fireing the click event? If you directly call btn.fireEvent('click'); without passing any params, it's normal that no params will get passed to the click handler function.

4 Nov 2010, 11:45 AM
Hi scarsick and thank you for your answer,

you mean that I have to code

btn.fireEvent('click', btn) ?

But what about the second argument (the argument evt) for example. It is peculiar that you have to pass arguments

4 Nov 2010, 12:19 PM
Yes this is what I mean..., but, why are you trying to manually fire the event? If you want to do something, you can just call a function directly, you don't have to fire the click event so that the function will get called...

4 Nov 2010, 2:17 PM
And if you don't use the event argument, then you don't have to pass it! Doesn't that stand to reason?