4

I've got a problem: I've got this property called 'active' on one of my models, it is either the string 'yes' or 'no', now I want to use this property to check a HTML radio button.

So when 'active' is 'yes' it should be checked otherwise it should not be checked. I've got this to work, however when I make an action that sets the 'active' property to 'no' or 'yes' the radio buttons checked status doesn't update.

Here's a bin: http://emberjs.jsbin.com/ohaSezo/3/edit.

When using a checkbox I get the same results: http://emberjs.jsbin.com/OWILUru/3/edit

I can't make sense of it, I think this should work, any ideas?

MrHus
  • 32,888
  • 6
  • 31
  • 31

2 Answers2

7

{{bind-attr}} doesn't work that way - it only binds one way. Here are some examples of how you'd go about this:

Use {{view Ember.Checkbox checkedBinding="car.active"}}: jsBin example

Or use a custom implementation of Ember.RadioButton - {{view Ember.RadioButton checkedBinding="car.active"}}: jsFiddle example

Credit for Ember.RadioButton: Thoughts & Ramblings of a Software Developer.

EDIT: Updated link as per Steve H.'s comment - thanks!

chopper
  • 6,649
  • 7
  • 36
  • 53
0

In addition to chopper's answer, I fix the first jsBin example : http://jsbin.com/ziyililetogi/2/edit. You can use {{view Ember.RadioButton selectionBinding="car.active" value="true" name="car"}}.

splanquart
  • 51
  • 1