I’ve successfully setup my FilteringSelect to query my server for items dynamically using the JsonRest store. My problem is when I try to initially set the dropdown with specific value.
<div id="ddThings"></div>
<script type="text/javascript">
dojo.ready(function () {
var storeThings = new dojo.store.JsonRest({ target: "/Things/" });
var ddThings = new dijit.form.FilteringSelect({
name: "thingId",
searchAttr: "name",
autoComplete: true,
value: "5",
missingMessage: "This is required",
placeHolder: "Select a Thing",
store: dojo.data.ObjectStore({ objectStore: storeThings })
}, "ddThings");
ddThings.startup();
//ddThings.set("value", "5");
});
When I set value to “5” or using ddThings.set I can see the filteringselect querying my server and passing in an “id” value. I return a collection of things with the single item in it. I expected it to populated the filteringselect with the item I returned. But, instead nothing happens.
The returned JSON looks like this
[
{
"id":"5",
"name":"Example"
}
]
One interesting note is that if I set “displayedValue” to “Example” (whatever the name is) then I can see it hit the server, find a match and return it and it actually populates the dropdown with the matching item. I want this behavior but by using the value/id of the item, not the display/name of it.
When the JsonRest Store makes a request for a specific item by its id the response must be a single item instead of a collection.
{ "id":"5", "name":"Example" }