PDA

View Full Version : MVC event bubbling - bug or is it just me ?



kef4e
24 Oct 2011, 11:23 PM
Hi,

I am not sure if this is a bug, or it is just me, so I will post here just in case :)

Until recently I used ExtJS 4.02a to create an MVC app. I uprated to 4.07, and a strange bug appeared.

In my app there is event bubbling , so that when a field is changed within a form the form is notified. I was controlling this event from the Controller like this:


this.control({
'app_formpanel': {
change: function (p){
// do something

}
}
});

however,

after the upgrade this doesn't work,

I have to control the bubble event like this:


this.control({
'app_formpanel': {
afterrender: function (p){
p.on('change',function (){
// do something
});

}
}
});

Is there any specific reason why in 4.07, handling bubbled events must be done by appending an event handled after render, and not just as regular events (in MVC)?
Is it just me or is this a bug ? Did somebody else encounter this after using 4.07 ?

p.s. I apologize for posting this twice, but I think here is a better place to ask this question, than the 'Discussions'. The moderators can delete the thread in 'Discussions'. 10x :)

mitchellsimoens
25 Oct 2011, 2:21 PM
Why not just setup a ComponentQuery to listen for the change event? No need to bubble.

kef4e
26 Oct 2011, 6:37 AM
Hi,

Thanks for the answer. I am not quite sure what you mean by setting up a ComponentQuery to listen.
Could you please give me some hints on this ?

mitchellsimoens
26 Oct 2011, 6:39 AM
this.control({
'app_formpanel field' : {
change: someFunction
}
});

What this does is gets all 'field's within 'app_formpanel' so since textfield, combobox, etc eventually extend field, this ComponentQuery will listen for the change event on those fields (all subclasses of field).

kef4e
26 Oct 2011, 7:26 AM
Ahaa, yep, this is a good idea ! I usually avoid assigning events to multiple components in this manner, because it might result in unwanted behavior.

10x again.