Willem de Wit
Willem de Wit

Reputation: 8732

Ember.Select valueBinding with multiple set to true doesn't work

I got this demo from the Ember documentation. It is a select-box with a value assigned.

App.programmers = [
  Ember.Object.create({firstName: "Yehuda", id: 1}),
  Ember.Object.create({firstName: "Tom",    id: 2})
];

App.currentProgrammer = Ember.Object.create({
  id: 2
});

View:

{{view Ember.Select
   contentBinding="App.programmers"
   optionValuePath="content.id"
   optionLabelPath="content.firstName"
   valueBinding="App.currentProgrammer.id"}}

This case works and the "Tom"-item is selected.

When I add the attribute: multiple="true" to the Ember.Select, the "Tom"-item is still selected. But I want that multiple items already are selected, so I changed App.currentProgrammer to this:

App.currentProgrammer = [
  Ember.Object.create({id: 1}),
  Ember.Object.create({id: 2})
];

But now nothing is selected anymore. Should I change the valueBinding-attribute?

Upvotes: 1

Views: 1652

Answers (1)

Nikolay
Nikolay

Reputation: 113

You may use selectionBinding instead: Fiddle

HTML:

<script type="text/x-handlebars">
{{view Ember.Select
    multiple="true"
    contentBinding="App.content"
    optionValuePath="content.type"
    optionLabelPath="content.label"
    prompt="Select a value"        
    selectionBinding="App.types"        
}}
{{#each App.types}}
    {{type}}
{{/each}}
</script>

JS:

App = Ember.Application.create({});

App.content = [
    {label: "This is type 1", type: "type1"},
    {label: "This is type 2", type: "type2"}
];

App.types = [
    App.content[0], App.content[1]
];

I agree that valueBinding is still not working.

Upvotes: 4

Related Questions