Jane Wilkie
Jane Wilkie

Reputation: 1743

Specifying a default selected value for ComboBoxes (dojo 1.7)

I am using dojo1.7 and ComboBoxes and I am having a problem setting default values. I noticed that setting value works correctly (as it should of course :-)....

<div data-dojo-type="dojo.store.Memory" data-dojo-id="stateStore" data-dojo-props="data: [{id: 'y', name: 'yes'}, {id: 'n', name: 'no'}]"></div>

<input data-dojo-type="dijit.form.ComboBox" data-dojo-props="store:stateStore, searchAttr:'name'" value="yes" name="state" id="stateInput">

I noticed that when you take out the value="yes" attribute, the ComboBox no longer has a default selected value from the store.

Is there some way that you can set the default value to the first value in a store? Reason I ask this is because I plan on using a lot of dynamic generated JSON data and being able to just "default to the first value" would be very beneficial.

Janie

Upvotes: 0

Views: 1018

Answers (1)

PEM
PEM

Reputation: 1978

I'm not sure how to do that declaratively but :

  • the code that is writing the html, can you maybe have it write the first element in value?
  • programmatically you'd fetch all items from store, then pick the first (in the onComplete(items), and set the value to your items[0].name or something similar...

If you can do the programmatic trick, it might allow for finer grained operations.

Upvotes: 2

Related Questions