Login Register

Filtering Select how do I set the default value

I have a filtering select field which requires it's initial value to be set. This value is based on data which is loaded initially. I'm trying to use the setValue and setDisplayedValue options with out much luck. I'm sure there's a simple way to set the value of a filter select when the page loads. What am I missing.

Thanks,
Salman

If you create your filtering

If you create your filtering select with code instead of markup, you can pass it an initial value like this:

var mySelect = new dijit.form.FilteringSelect({store: selectOptions, value: 1, style: "padding-left: 5px;"}, dojo.byId("mySelectDiv"));

I believe you can do the same thing with markup by adding a "value=" attribute, but I haven't tried that.

If you create the select

If you create the select through markup it doesn't work. In my case the select is data driven through a ItemFileReadStore which calls a url. Apparently setting the default value is not all that straight forward. I had to dig up a lot of site to figure this out. See http://www.dev411.com/blog/2006/06/14/dojo-setting-the-combobox-default-... . I finally settled on doing this through the method described out here. Let me know if there's a better way to do this.

Thanks
-S

If you create the select, you can set the default value this way

Since the item won't get highlighted when it's selected and there's not set select method in FilteringSelect, you can set the default value this way:

store = new dojo.data.ItemFileReadStore({data: data});
mySelect.store = store;
mySelect.setValue(data.items[0].someAttribute)