Reputation: 4286
I have a combobox for which I have a validation that a change in selection should be reverted back on meeting a condition.
I have detected the condition but when I change the value and displayedValue of combobox, the onChange associated with the combobox gets fired. Following is the code I am using to change the selection:
dijit.byId('scheduleName').set('value',val,false);
dijit.byId('scheduleName').set('displayedValue',displayVal,false);
I have also tried to set the onChange to blank before firing above code and then re attaching the onChange code as below:
dojo.connect(dijit.byId('scheduleName'),'onChange','');
dijit.byId('scheduleName').set('value',scheduleNameVal,false);
dijit.byId('scheduleName').set('displayedValue',trim(String(scheduleNameName)),false);
dojo.connect(dijit.byId('scheduleName'),'onChange', "hideGrid");
hideGrid is a javascript function. I am using Dojo 1.8
Upvotes: 0
Views: 1927
Reputation: 7352
Set only value, not displayedValue
myComboBox.set("value", value, false);
then only watch
callback is fired, not dojo/on
or onChange
.
Check this jsFiddle out to see differencies: http://jsfiddle.net/phusick/d7ymY/
Note: If you need to trim()
displayedValue consider a custom setter
or dojo/aspect::before
.
Upvotes: 3
Reputation: 8162
You should use dojo.disconnect
instead of
dojo.connect(dijit.byId('scheduleName'),'onChange','');
Example:
var hndl, sched = dijit.byId('scheduleName');
var fnWireOnChange = function(){
hndl = dojo.connect(sched,'onChange', 'hideGrid');
};
dojo.disconnect(hndl);
sched.set('value',scheduleNameVal,false);
sched.set('displayedValue',trim(String(scheduleNameName)),false);
fnWireOnChange();
As a side note, connect/disconnect
has been deprecated in favor of dojo/on
https://dojotoolkit.org/reference-guide/1.8/dojo/on.html#dojo-on
Upvotes: 1