Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone radio button change event

Tags:

backbone.js

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
like image 964
Mikkel Nielsen Avatar asked Jan 18 '26 10:01

Mikkel Nielsen


1 Answers

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() {
...
like image 93
Rida BENHAMMANE Avatar answered Jan 20 '26 15:01

Rida BENHAMMANE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!