Created
June 3, 2014 17:01
-
-
Save courajs/84f5b113de2db762cb1d to your computer and use it in GitHub Desktop.
Cooler magic binding radio buttons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var RadioView = Ember.View.extend({ | |
tagName: 'input', | |
type: 'radio', | |
attributeBindings: ['type', 'htmlChecked:checked', 'value', 'checked:name'], | |
change: function(){ | |
this.set('selectedValue', this.get('value')); | |
}, | |
htmlChecked: function(){ | |
return this.get('value') === this.get('selectedValue'); | |
}.property('value', 'selectedValue'), | |
setupBindings: function() { | |
if (this.binding) this.binding.disconnect(this); | |
this.binding = Em.Binding.from("context." + this.get('checked')).to('selectedValue'); | |
this.binding.connect(this); | |
}.on('init').observes('checked', 'context') | |
}); | |
export default RadioView; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment