2
votes

I am trying to use a Ember.Select on a boolean attribute on my model. The problem is that it is converting my attribute to an object {} and no binding occurs.

My model has an isActive flag

isActive: DS.attr('boolean'),

Here is the ember select in my template

            {{view Ember.Select
                viewName="isActive"
                content=controller.yesNo
                optionLabelPath="content.key"
                optionValuePath="content.value"
                selection=model.isActive
                class="form-control"
                disabled=true}}

In my router I set the yesNo array on the controller (as an aside, I am not sure if this is the correct place to do this, this one is simple but some of my selects require querying the database using this.store.find('accounts') so I think these go in the route not the controller).

setupController: function(controller, model) {
    this._super(controller, model);

    controller.set('yesNo', [
        {key : 'Yes', value : true},
        {key : 'No', value : false}
    ]);
}

I have also tried passing the boolean values as string but it does not work.

    controller.set('yesNo', [
        {key : 'Yes', value : 'true'},
        {key : 'No', value : 'false'}
    ]);

update

From ember inspector, when I select an item it is returning the whole object { key: Yes, value: true } or { key: No, value: false }. I wan't it to return the value property only.

1

1 Answers

4
votes

selection binds the whole object. value will bind just the property specified in optionValuePath to the property you specify. Thus, use value instead of selection if you just want the binded property to be a boolean. Therefore, in your select's handlebars in the template use:

{{view Em.Select
  // Properties...
  // More properties...
  value=isActive
}}

Sidenote:

You don't need to specify controller in content=controller.yesNo. You can just say content=yesNo.