David
David

Reputation: 320

Initially selected value from store in dijit.form.FilteringSelect

I have a dojo.data.ItemFileReadStore as follows:

var partyStore = new dojo.data.ItemFileReadStore({
    id: 'partyStore',
    data: {
    label:'name', 
    items:[
       {value:'APPLES', name:['Apples']},
       {value:'ORANGES', name:['ORANGES']},
       {value:'PEARS', name:['PEARS']}
    ]}
});

and a dijit.form.FilteringSelect as:

var partyList = new dijit.form.FilteringSelect({
    id: "partyLookup", 
    name: 'partyLookup',
    store: partyStore,
    searchAttr: "name"}, infoDiv);

How can I make the initially selected value be Oranges? I have tried various entries for the value in the FilteringSelect so have left it out in this example.

Upvotes: 2

Views: 6637

Answers (2)

David
David

Reputation: 320

I had missed off the "identifier" from the store data. It seems without the identifier being set it indexes them ie. 0,1,2,3,4...

Once I set:

identifier: 'value'

the current value of the FilteringSelect comes back as the 'value' form the data.

Sorry to answer my own question, thanks to anyone who helped or took a look.

Upvotes: 1

Richard Ayotte
Richard Ayotte

Reputation: 5080

Your data store doesn't seem right. Try changing it to:

var partyStore = new dojo.data.ItemFileReadStore({
    identifier: 'value',
    items:[
       {value:'APPLES', name:'Apples'},
       {value:'ORANGES', name:'ORANGES'},
       {value:'PEARS', name:'PEARS'}
    ]
});

You can then set the value of the dijit.

partyList.set('value', 'ORANGES');

Upvotes: 3

Related Questions