Skip to content

Instantly share code, notes, and snippets.

@xypaul
Created April 9, 2015 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xypaul/1bfc92a7ca53442677bd to your computer and use it in GitHub Desktop.
Save xypaul/1bfc92a7ca53442677bd to your computer and use it in GitHub Desktop.
Radio buttons - Ember
// Yes there is no template
App.RadioButtonComponent = Ember.Component.extend({
tagName: 'input',
type: 'radio',
value: null,
attributeBindings: [ 'checked', 'name', 'type', 'value' ],
checked: function () {
return JSON.parse(JSON.stringify(this.get('value'))) == JSON.parse(JSON.stringify(this.get('groupValue')));
}.property('value', 'groupValue').readOnly(),
change: function () {
this.set('groupValue', this.get('value'));
Ember.run.once(this, 'checked'); //manual observer
}
});
{{#each option in s.d.field_options.options}}
{{radio-button name=uniqueRadioID value=option.label groupValue=s.record.Value}} {{option.label}}
{{/each}}
@xypaul
Copy link
Author

xypaul commented Apr 9, 2015

Probably also needs a wrapper called radio-buttons, where you just give it an array of options and a value and it'll do everything, just like the dropdown component.

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