FullStack FullStack - 1 month ago 7
jQuery Question

How to detect events on entire document in Meteor JS?

It's really as simple as that. I currently have in my template events, but it is not working:

'keyup': function(event) {
event.preventDefault();
console.log("KEYUP");
}


Update: it appears to be a generic bug in the framework. I would appreciate it if anyone could share a manual hack I could employ that doesn't involve using someone else's packages.

Update 2: I have solved this problem as shown below.

Answer

All of a sudden my original code works. Maybe the good folks at Meteor has fixed the problem, yay!

Here's what works for me on 0.9.3.1:

Template.template_name_here.events({
  'keyup': function(event) {
    event.preventDefault();
    console.log("KEYUP");
  }
});

Meteor can even handle multiple events with a single handler like this:

Template.template_name_here.events({
  'keyup, click': function(event) {
    event.preventDefault();
    console.log("KEYUP OR CLICK");
  }
});

Awesome!

Comments