0
I have a radio-button.js component, a radio-options.js controller, and the radio-options.hbs template. I need to call the optionChanged function that is the controller in the component, currently the way it is gives the following error: Uncaught Error: had the Handler action for: optionChanged
COMPONENT
import Ember from 'ember';
var RadioView = Ember.Component.extend({
tagName: 'input',
type: 'radio',
attributeBindings: ['type', 'htmlChecked:checked', 'value', 'name'],
change: function(){
this.set('selectedValue', this.get('value'));
this.sendAction('optionChanged', 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 = Ember.Binding.from("context." + this.get('checked')).to('selectedValue');
this.binding.connect(this);
}.on('init').observes('checked', 'context')
});
export default RadioView;
CONTROLLER
import Ember from 'ember';
var RadioOptionsController = Ember.Controller.extend({
answer: Ember.computed.alias('parentController.answer'),
radioName: function(){
return 'question-' + this.get('parentController.model.id');
}.property('parentController.model'),
actions: {
optionChanged: function(selectedValue) {
console.log('value: '+selectedValue);
this.get('answer').set('text', selectedValue);
this.send('saveAnswer');
}
}
});
export default RadioOptionsController;
TEMPLATE
{{#each model as |option|}}
<li>
<label>{{radio-button name=radioName checked='answer.text' value=option.text}} {{option.text}}</label>
</li>
{{/each}}
I think it worked (although I’m not recording in the API). In Template I did exactly as I said, in Component it looks like change: Function(){ this.set('selectedValue', this.get('value')); this.sendAction('optionChanged', this.get('value')); }, and in the controller I didn’t change anything because the function was already working. Thank you very much.
– Bruno Martins