Reputation: 865
I am new to the Dojo framework, and try to subscribe an onChange event for a ComboBox Dijit in the code grammatically. But for some reason, my event handler function can't catch this event. Could you help me to find out where am I wrong?
<div id="container" style="padding: 5px;">
<select data-dojo-type="dijit/form/ComboBox" name="state" id="stateInput">
<option>Apples</option>
<option selected>Oranges</option>
<option>Pears</option>
</select>
</div>
require([ 'dijit/form/ComboBox',
"dojo/on",
"dijit/registry"
], function(ComboBox, on,registry){
var comboBoxDigit2 = registry.byId("stateInput");
on(comboBoxDigit2,"onChange", function (e) {
alert("I am an alert box!");
});
});
Thanks,
Wei
Upvotes: 0
Views: 64
Reputation: 734
There are a few errors in this code.
require passes the array to function in the same order. You are currently passing "dojo/on" and "dijit/registry" into ComboBox, on, and registry. You need to require "dijit/form/ComboBox"
The format for data-dojo-type should be a path ie data-dojo-type="dijit/form/ComboBox"
The format for on is typically on(element, eventname, function)
although I believe you can do it the way you are doing it.
Edit:
on works with the event ie
on(combobox, "change", function(value) {...});
You original fiddle was not being parsed as a dijit, it was just a plain html select, so the call to registry was failing. I've updated the fiddle. http://jsfiddle.net/vdmhU/13/
Upvotes: 2