PDA

View Full Version : Suspend/resume events help



drian
1 Jun 2011, 6:33 AM
Hi guys,


I have an event listener on "change" for a radiogroup. The radio group is inside a form, into which i load some data with setValues().

How can i suspend the change event for the radiogroup when i load setValues() on the form.

I've tried to suspendEvents() before i use form.setValues() and then call resumeEvents() again but it doesn't seem to work.

Am i doing something wrong?

skirtle
1 Jun 2011, 6:40 AM
The approach you've described sounds correct. Are you calling suspectEvents() on the right object (i.e. the RadioGroup)? Any code you could post to give us more insight into what you're doing?

drian
1 Jun 2011, 6:48 AM
Thanks for the quick reply!

the radiogroup


,{
xtype: 'fieldset',
width: 160,
x: 160,
items: [{
ref: '../../../../payment_type',
xtype: 'radiogroup',
hideLabel: true,
items: [{
xtype: 'radio',
name: 'payment_type',
boxLabel: 'Type 1',
inputValue: 1,
checked: true,
anchor: '95%'
},{
xtype: 'radio',
name: 'payment_type',
boxLabel: 'Type 2',
inputValue: 2
}],
listeners: {
change : function(group, checked){
this.setPayment(checked.inputValue);
},
scope: this
}
}]
}


the function that loads data in the form


loadData : function(dataToLoad){
this.payment_type.suspendEvents();
this.formAddEdit.getForm().setValues(dataToLoad.details.data);
this.payment_type.resumeEvents();
}
},


The payment_type radiogroup is inside the formAddEdit form.

I'm sure i'm calling suspendEvents correctly because if i don't, my radiogroup change event won't be triggered anymore.

It's like setValues() on the form works asynchronus.

skirtle
1 Jun 2011, 6:26 PM
Looks like you're correct, the change event is fired asynchronously for a RadioGroup. When the check event is fired on a radio button it calls a method called fireChecked() on the RadioGroup. This creates a DelayedTask which calls bufferChecked() on a 10ms delay. This fires the change event.

This is a nuisance. The easiest way I could find to work around this was to suspend events on each of the individual radio buttons. This stops the check event firing, which prevents any of the above happening.

drian
2 Jun 2011, 5:53 AM
Thanks for digging into the code. Suspending the events on the radio buttons solved the issue.