Skip to content

Instantly share code, notes, and snippets.

@courajs
Created June 3, 2014 18:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save courajs/7973c9bec27f0e0a3508 to your computer and use it in GitHub Desktop.
Save courajs/7973c9bec27f0e0a3508 to your computer and use it in GitHub Desktop.
Simpler explicit name radio buttons
import RadioView from '../views/radio';
export default Ember.Handlebars.makeViewHelper(RadioView);
<label>
{{radio-button name='thing' value='one' checked=selection}} One
</label>
<br>
<label>
{{radio-button name='thing' value='two' checked=selection}} Two
</label>
<br>
<div>Currently selected: {{selection}}</div>
var RadioView = Ember.View.extend({
tagName: 'input',
type: 'radio',
attributeBindings: ['type', 'htmlChecked:checked', 'value', 'name'],
htmlChecked: function(){
return this.get('value') === this.get('checked');
}.property('value', 'checked'),
change: function(){
this.set('checked', this.get('value'));
}
});
export default RadioView;
@blessanm86
Copy link

I tried this and it works but for some reason my observers only fire once. I set the value and observer like this.

export default Ember.ObjectController.extend({
  selection: "one-way",
  selectionChanged: function() {
    alert(this.get('selection'));
  }.observes('selection')
});

Can you reproduce this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment