Reputation: 6020
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.
Upvotes: 4
Views: 2151
Reputation: 403
Currently Meteor is properly handling <body>
events, unless you are using a renderer which takes over rendering of the template. An example of this is Kadira:blaze-templates which will override default Meteor rendering of template (for use with FlowRouter), or Iron Router.
Luckily there is a simple package to restore this functionality called gwendall:body-events.
Upvotes: 0
Reputation: 6020
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!
Upvotes: 2
Reputation: 5656
Unfortunately there is a bug in meteor (source) that events don't fire on UI.body.template
. You can use a package meteor-body-events to patch that, and attach keyup
event on entire document.
Upvotes: 4