|
// {{ 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 |
|
} |
|
}); |
great