javascript - Recording values of radio buttons in ember -


i new ember (using version 0.2.3). have component few computed values. gather these computed values input fields:

export default component.extend({   loanamount : 200000,   deductible : 0,   debtint : 5,    getloancosts: computed('loanamount', 'debtint', function(){     return (get(this, 'debtint')/12) * get(this, 'loanamount');   }) 

on template.hbs, have input field {{ input value=loanamount }} , can call {{getloancosts}} in template.hbs, show computed cost. works great text/number inputs.

however, need have radio button input 2 values (yes , no). should line deductible value in component (i.e. loan deductible?). however, if do:

yes {{ input type="radio" name="deductible" value=deductible }} no {{ input type="radio" name="deductible" value=deductible }} 

i can't set values these 2 inputs, can straight html. if set value=0 , value=1, never update in component. how can update deductible in component based on whether yes or no selected?

yeah ember doesn't have built in support radio button. try making own component! , make own mean shameless steal 1 internet.

import ember 'ember';  export default ember.component.extend({   tagname: 'input',   type: 'radio',   attributebindings: ['type', 'htmlchecked:checked', 'value', 'name', 'disabled'],    htmlchecked: function() {     return this.get('value') === this.get('checked');   }.property('value', 'checked'),    change: function() {     this.set('checked', this.get('value'));   },    _updateelementvalue: function() {     ember.run.next(this, function() {       this.$().prop('checked', this.get('htmlchecked'));     });   }.observes('htmlchecked') }); 

and in component, radio buttons still have values, binding of selection passed in checked property:

yes{{radio-button value='1' checked=choice}} no{{radio-button value='0' checked=choice}} 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -