PDA

View Full Version : beforechange event on combobox



gabrikid
9 May 2014, 5:18 AM
Hi. Why comboboxes does not have an beforechange event?

In my case, i have some fields that are dependents of the combobox value. So, if the combobox value changes, and if the fields are set, it is necessary to inform the user that those fields are not coherent anymore. So, the user has two choices, accept the value and clear the dependent fields OR do not accept the value and keep everything as it is.
The thing is, if i do this with the change event, and if the user rejects the change, i will set the value to the old value, but the prompt will appear again and again, everytime the user rejects the change... This does not make any sense at all. To solve this, i need to set a flag to true, so that the change handler does not run again. It should not be this way. It would be so much easier with the beforechange event.

jsakalos
9 May 2014, 11:27 PM
Form fields do not have beforeXXXX events. You could maybe solve the problem by suspending events while you manipulate fields values programmatically and resume them afterwards to avoid the infinite event loop.

Dev@QLP
10 May 2014, 6:12 AM
You could maybe solve the problem by suspending events while you manipulate fields values programmatically and resume them afterwards to avoid the infinite event loop.

Unless your listeners are on a controller and suspendEvents is ignored. :((

jsakalos
10 May 2014, 11:48 AM
Well, you can suspend events also on controller: http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.app.Controller-method-suspendEvents

varsos
11 May 2014, 6:16 PM
"...This does not make any sense at all" is right, if you assume that the change event means "user changed event", but this is not true in Extjs 4.x.

Many of us migrating apps from older Extjs to 4.x were in for a surprise in this area.
The checkChangeEvents propery controls what triggers the "change" event and by default pretty much everything a user does of anything you do to change the field's value programmatically.

So, Mr. Sakalos' suggestion is a good idea, unless you really want to alter this behavior globally and make the change event fire with only user interactions.

jsakalos
11 May 2014, 10:47 PM
Now "change" means: somebody called setValue. However, you can call setRawValue (http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.form.field.Text-method-setRawValue) to bypass change, validation, conversions.

Dev@QLP
12 May 2014, 6:13 AM
Well, you can suspend events also on controller: http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.app.Controller-method-suspendEvents

Thanks! I didn't know that.

gabrikid
13 May 2014, 8:33 AM
thanks for the support.

EDIT: actually, the suspendEvents can solve this issue, but i will not use it. but, this method, is usefull to load data into the form without the events being fired. thanks ;)