How to add event handler for dynamically created widgets in the controller?
How to add event handler for dynamically created widgets in the controller?
Hello Forum members,
I'm a newbie to ExtJs world. I started implementing a MVC based ExtJs 4 project. My problem is -
I have a view(myview.js) which contains a button. Whenever I click on that button (mycontroller.js) I'll create a new window which pops up on the parent window. This new window contains a button and now I need to handle click event for this button. How can I do it? Where should I write the event handler? I tried to do it in mycontroller.js itself. But it's not working as the window is getting created in the runtime. Can someone help me regarding this please?
It shouldn't matter that the window gets created later. If the window has an itemId or alias you can target it pretty easily. In your this.control call in your controller you can use a selector like
'#itemId button[text="Cancel"]'
Of course if you changed your button text then it wouldn't work, so you might want to target it differently. I try not to go too crazy with itemIds, but they are preferable to ids when you need to use something like that.