Ashwin Hegde
Ashwin Hegde

Reputation: 1771

Textarea event in Backbone.js

In my application then is some textarea with class "contentBlock".

and i am using for following code in backbone view:

 'change textarea': 'updateText'       

but the updateText function is not getting fired.

I want to fire the event when any text got change in the textarea.

Upvotes: 2

Views: 2898

Answers (2)

CBP
CBP

Reputation: 799

You should be using the keyup event (or some other key event) to listen for the text changing in the text area. Using Loamhoof's example:

var View = Backbone.View.extend({
    events: {
        'keyup textarea': 'test'
    },
    test: function() {
        alert();   
    }
});

new View({el: 'div'});

Upvotes: 4

Loamhoof
Loamhoof

Reputation: 8293

So... sadly, as we have too few elements to provide any answer, I'm simply providing you a working, simple example:

var View = Backbone.View.extend({
  events: {
    'change textarea': 'test'
  },
  test: function() {
    alert();   
  }
});

new View({el: 'div'});

http://jsfiddle.net/ZSgvy/

So, based on common mistakes: make sure your events are bounded to your view's element (if you specify an element which doesn't exist or you change it the wrong way afterwards, they won't), and make sure your textarea actually is a descendant of your view's element. Also, the way you do it, the textarea must not be the view's element itself.

Upvotes: 0

Related Questions