Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dojo Select onChange event firing when changing value programmatically

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); 
    }
like image 440
Justin Avatar asked Jul 12 '10 15:07

Justin


1 Answers

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;
like image 138
Bill Keese Avatar answered Sep 27 '22 00:09

Bill Keese