Sport
Sport

Reputation: 8955

backbone.js events not bind to fire action on text area

I have a text area in my template .i want to pass text value from text area to function (view ) change event. I bound the "change" event to textarea but action is not working.

template

<div id="replyt" class="commentArea">                                           <textarea id="rep" class="form-control" placeholder="What's on your mind ?" rows="2"></textarea>
    </div>

My view

var PostwallView = Backbone.View.extend({

 el: $("#content"),
     events: {

      'change #rep': 'test',// or which event i need

             },

My action

 test:function(e)
      {
      var val = $(e.currentTarget).val();
       alert( val );
    e.preventDefault();

     },

Here I used keyup and keydown. My event is working but action fire in first character when I am typing in text area

Upvotes: 2

Views: 628

Answers (2)

Nakul91
Nakul91

Reputation: 1245

"blur #rep":"yourMethod"


 yourMethod:function(){
 if($('#textArea').val() != null || '#textArea').val() != undefined){
  /*Call your other function here*/
}
}

Upvotes: 0

jgillich
jgillich

Reputation: 76287

The input and keydown/up events are triggered when the value changes or a key is pressed. I don't know when you expect change to trigger, but blur triggers when the textarea loses focus:

'blur #rep': 'test'

Upvotes: 1

Related Questions