Skip to content

Instantly share code, notes, and snippets.

@pwfisher
Forked from courajs/helpers-radio-button.js
Last active August 29, 2015 14:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save pwfisher/b4d27d984ad5868baab6 to your computer and use it in GitHub Desktop.
Save pwfisher/b4d27d984ad5868baab6 to your computer and use it in GitHub Desktop.
radio-button-component.js
// {{ radio-button name='dish' value='spam' groupValue=selectedDish }} Spam
// {{ radio-button name='dish' value='eggs' groupValue=selectedDish }} Eggs
//
App.RadioButtonComponent = Ember.Component.extend({
tagName: 'input',
type: 'radio',
attributeBindings: [ 'checked', 'name', 'type', 'value' ],
checked: function () {
return this.get('value') === this.get('groupValue');
}.property('value', 'groupValue'),
change: function () {
this.set('groupValue', this.get('value'));
}
});
{{ radio-button name='thing' value='one' groupValue=selection }} One
{{ radio-button name='thing' value='two' groupValue=selection }} Two
Currently selected: {{ selection }}
@vasilakisfil
Copy link

Nice but checked must be bound to an observer, not .property(). Also you should add an option to inject an action to be called when checked. My solution: https://gist.github.com/vasilakisfil/d055d9d2d9b56f684b42

@blimmer
Copy link

blimmer commented Oct 29, 2014

Great work. This is exactly what I was looking for. Also, here is a CoffeeScript version of this gist.

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