Trigger event on Textinput or Textarea value change MeteorJS

时间:2015-05-24 20:51:11

标签: javascript meteor

I want add the contents of a textarea (or a textfield) to a reactive variable and bind it to a view, similar to AngularJS double binding.

The problem to listen to keydown is that the last character will not be included. If I use keyup there will be a delay. Is there a way to listen to value change in a text field and immediately after it changes set the reactive variable?

Template.body.events({
     "keydown #textarea":function(){
         input.set( $('#textarea').val());
     }
 });

1 个答案:

答案 0 :(得分:1)

You can use the HTML5 input event which is probably better suited for what you need.

Template.body.events({
  "input #textarea":function(){
    input.set( $('#textarea').val());
  }
});