emberjs/ember.js — Issue #482: Ember.Select selectionBinding doesn't work on object properties
Author: quasipickle
Created: 2012-02-08 18:26:12+00:00
State: open

When selection binding an Ember.Select to an object property (like selectionBinding="controller.selected.id"), the binding doesn't work. The property is replaced by the whole model object when is changed.

Here is a workaround I was given on IRC:

```javascript
Status.Select = Em.Select.extend({
value: Ember.computed(function(key, value){
var content = this.get('content'),
self = this,
optionValuePath = this.get('optionValuePath');

if (value != undefined){
content.forEach(function(item, idx){
if (item.id && item.id == value)
{
self.set('selection', item);
return;
}
});

return value;
}

return this.get('selection')?
this.get('selection').id :
null;
}).property('selection').cacheable()
});
```

And a view that uses it:

```html
{{view Status.Select
contentBinding	= "Status.possibleHours"
valueBinding	= "content.returnHour"
optionLabelPath	= "content.label"
optionValuePath	= "content.id"
}}
```