1
votes

How do you get the id for the underlying record in a combobox with dojo? I've tried altering the following sample but all I can get is the text shown to the user (the "name" property of each array element), and NOT the state's two-letter abbreviation ("id" property).

http://dojotoolkit.org/reference-guide/1.10/dijit/form/ComboBox.html#id3

thanks. PS, I'm a total noob with dojo. This is my first experiment with it.

3

3 Answers

2
votes

It's like @CodeCrisis said, you can get the item by using dijit.byId('stateSelect').item. Though I'm not really pleased with how outdated the docs are (the dijit.byId()command is deprecated), this is a proper 1.10 solution:

query("button").on('click', function() {
   console.log(comboBox.get('item')); 
});

This will return the selected record in the store (containing both the id and name properties in this case).

A full, working example can be found here: http://jsfiddle.net/zt6xggL8/

1
votes

How about this...
base on the link given
http://dojotoolkit.org/reference-guide/1.10/dijit/form/ComboBox.html#id3
change this onclick function

onClick="alert(dijit.byId('stateSelect').get('value'))"


into

onClick="alert(dijit.byId('stateSelect').item.id)"


i know this is not the best answer but i hope this will help you..

check out the answer of Philippe
Dojo : ComboBox selected and show data id

hehehe... :) just passing by...

1
votes

Not the prettiest but this works. Basically need to query the 'store' variable for the name that is being displayed when you just use 'value'. [0] denotes the first object in the store list, so if you have multiples with the same name, you'll need to use the foreach() function.

<button onClick="var namevar=dijit.byId('stateSelect').get('value');
                 alert(dijit.byId('stateSelect').get('store').query({name:namevar})[0].id);">
    Get value
</button>