I have a dojo (dijit) select dropdown that calls a js function onChange. I was expecting this to only call the onChange function when the user changes the value in the dropdown, however, it even calls the onChange function when I programmatically change the value of the dropdown from js code. How do I get it to only call the function when the user changes the dropdown value? It shouldn't call the function when I programmatically change the value.
<select jsId="ddlBoundaryType" id="ddlBoundaryType" name="ddlBoundaryType"
dojoType="dijit.form.Select">
<option value="0">Circle</option>
<option value="1">Polygon</option>
</select>
dojo.addOnLoad(InitBoundaries);
function InitBoundaries() {
dojo.connect(dijit.byId("ddlBoundaryType"), 'onChange', Boundaries_ChangeBoundaryType);
}
Often people solve this by using the priorityChange flag:
myWidget.set("value", 1234, false);
That will solve your problem except for subtle issues where the value is originally 123, you set it programatically to 456, and then the user sets it back to 123, in which case there won't be an onChange() event for the user action either.
For that reason you can additionally do:
myWidget._lastValueReported=null;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With