Question

I'm trying to hook a lister to radio button changes. But for some reason I cant get this to work:

What I got is thsi:

html:

<input type="radio" name="hat" value="1">
<input type="radio" name="hat" value="2">
<input type="radio" name="hat" value="3">

im trying to set a lister up in my view's render method like this:

this.listenTo(this, 'change input[type=radio]', this.changedRadio);

But chaging the radio button dosen't result in "changedRadio" beeing called.

instead i get this in the console:

Unable to get property 'controlMap' of undefined or null reference
Was it helpful?

Solution

In your code you are listening to the change event in your view and a Backbone view won't trigger that event.

Try to add it to the view events like this:

events: {
    'change input[type=radio]': 'changedRadio'
},

changedRadio: function() {
    ...
},

render: function() {
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top