Skip to content

Instantly share code, notes, and snippets.

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 kenkogi/35f518eab57aa544bf1ba5b0e506788b to your computer and use it in GitHub Desktop.
Save kenkogi/35f518eab57aa544bf1ba5b0e506788b to your computer and use it in GitHub Desktop.
// {{ radio-button name='dish' value='spam' groupValue=selectedDish selectedAction='testAction' }} Spam
// {{ radio-button name='dish' value='eggs' groupValue=selectedDish }} Eggs
//
/*
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'input',
type: 'radio',
attributeBindings: [ 'checked', 'name', 'type', 'value' ],
checked: function () {
if (this.get('value') === this.get('groupValue')) {
Ember.run.once(this, 'takeAction'); //this actually fires 3 times :/
return true;
} else { return false; }
}.observes('groupValue'),
takeAction: function() {
this.sendAction('selectedAction', this.get('value'));
},
change: function () {
this.set('groupValue', this.get('value'));
}
});
*/
import Ember from 'ember';
export default Ember.Component.extend({
init() {
this._super();
Ember.run.once(this, 'isChecked'); //manual observer
},
tagName: 'input',
type: 'radio',
attributeBindings: [ 'checked', 'name', 'type', 'value' ],
checked: null,
isChecked() {
if (this.get('value') === this.get('groupValue')) {
Ember.run.once(this, 'takeAction');
this.set('checked', true);
} else {
this.set('checked', null);
}
},
takeAction() {
this.sendAction('selectedAction', this.get('value'));
},
change() {
this.set('groupValue', this.get('value'));
Ember.run.once(this, 'isChecked'); //manual observer
}
});
{{ radio-button name='thing' value='one' groupValue=selection selectedAction='testAction' }} One
{{ radio-button name='thing' value='two' groupValue=selection }} Two
Currently selected: {{ selection }}
@Bishwazid
Copy link

great

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