PDA

View Full Version : catch change event in controller



lpe2012
18 Sep 2012, 9:14 AM
Hi,

I'm using EXTJS 4.1 and have a question that someone may be able to help.

How can I catch a change event in my controller when someone selects or changes an item, I can catch in my view using the change event but I will like to be able to do it in the controller

thanks

Tim Toady
18 Sep 2012, 10:28 AM
You are still catching the change event, just not using the listeners config. In your controller's init function use the control function as seen in the example. Just use the proper selector to target your component.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Controller-method-control

tangix
19 Sep 2012, 1:48 AM
As Tim said, use the following in the Controller's init():
(I just copied the code from my project so don't expect it to run. Showing some different selectors and also the use of "action" config on a button that I find very useful)


this.control({
'#topicgrid': {
itemdblclick: this.editTopic
},
'edittopicwindow button[action=save]': {
click: this.saveTopic
},
'edittopicwindow button[action=cancel]': {
click: this.closeTopicWindow
},
'#topicgrid > toolbar > button[action=add]': {
click: this.addTopic
},
'#topicgrid > toolbar > button[action=edit]': {
click: this.editGridTopic
},
'#topicgrid > toolbar > button[action=delete]': {
click: this.deleteGridTopic
}
});

FireBug's Console CLI is your friend to get the selectors right, I find myself missing doing many Ext.ComponentQuery.query() in FireBug to explore the structure.