0

I was using dijit.form.ComboBox, but the requirement has changed, and now dijit.form.Select is more appropriate.

However, after changing the widget type I get an error:

TypeError: _b6d.getLabel is not a function

From the documentation http://dojotoolkit.org/reference-guide/1.10/dijit/form/Select.html I see that dijit.form.Select expect fields id and label in the Store, while my Store has id and name.

The documentation gives no example how to override that defaults. So, how can I specify the id and label attributes for dijit.form.Select?

My data looks like that:

[{"id":1,"name":"Item 1"},{"id":2,"name":"Item 2"},{"id":3,"name":"Item 3"}]

In case it's not possible, what dijit widget can I use for selection restricted only to items from Store?

3 Answers 3

3

There is a labelAttr property on the dijit/form/Select which you can use to change the name of the label attribute.

For example:

new Select({
    store: myStore,
    labelAttr: "name" // Now the name attribute will be used
}, "mySelect");

If you also like to change the attribute used for the ID (it's not necessary in this case, but you asked how to specify that one as well), then you should look at the idProperty of the dojo/store/Memory, for example:

var myStore = new Memory({
    idProperty: "id",
    data: [{
        "id":1,
        "name":"Item 1"
    }, {
        "id":2,
        "name":"Item 2"
    }, {
        "id":3,
        "name":"Item 3"
    }]
});

A full example can be found on JSFiddle: http://jsfiddle.net/NvKgH/

1

You can use a FilteringSelect to restrict the selection to only the items that are in the store. And it shouldn't be much trouble to implement it, because both ComboBox and FilteringSelect use dijit/form/ComboBoxMixin to provide the combobox functionality.

0

I think you have misread the documentation.
It mentions over here that the data from the store must have id and label attributes, not value and label attributes.
The id of the store will be the value you get using the get("value") call.
For getting the value you need to use get("value") function on the widget i.e

widget.get("value")

and for label I am assuming that it is

widget.get("label")


[{"id":1,"name":"Item 1","label":"Item 1"},{"id":2,"name":"Item 2","label":"Item 2"},{"id":3,"name":"Item 3","label":"Item 3"}]
1
  • Well, it didn't change as much. My data doesn't have label attribute. I need to say that the Select should use name instead. Otherwise it won't work. Commented Jul 23, 2014 at 7:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.