Search code examples
ember.jscheckboxcomponentsember-cli

this.sendAction is not working for checkbox


Why is this.sendAction not working in the below code? I get the error

Uncaught TypeError: this.sendAction is not a function

//components/check-box2 import Ember from 'ember';

export default Ember.Checkbox.extend({
  checkChange: Ember.observer('checked', function () {
    this.sendAction('action', {
        checked: this.get('checked'),
        value: this.get('value')
      });
  })
});

this.send() seems to be working

import Ember from 'ember';

export default Ember.Checkbox.extend({
  checkChange: Ember.observer('checked', function () {
    this.send('internalAction', this.get('checked'), this.get('value'));
  }),

  actions: {
    internalAction: function (x, y) {
      console.log('calling internal change with value', x, y);
      this.sendAction('action', {
        checked: x,
        value: y
      });
    }
  }
});

component is used as below:

{{check-box2 checked=true name="namedBox" value="xyz" action="checkCheckbox"}}

From what i could gather Ember.Checkbox is extending a component so we should be able to do this.sendAction http://emberjs.com/api/classes/Ember.Checkbox.html


Solution

  • What version of Ember do you use? Since you tagged the question with ember-cli I assume it's 1.13.8 or less. Ember.Checkbox extends Ember.View in your case: 1.13.10. This was changed in 2.0 since they are getting rid views at all.

    So you can't use this.sendAction on Ember.View but you can use this.controller.send instead.