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
  • 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 }}
@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