Reputation: 884
I am attempting to use the following JQuery code to call a Meteor method:
$('html').bind('paste', function(e) {
Meteor.call('click', document.getElementById("box").value);
});
I put this code in a script tag in the html and confirmed that the code is called when I need it to be called. However, rather than calling the Meteor method ("click") paste simply pastes the line:
Meteor.call('click', document.getElementById("box").value);
into the textarea I'm attempting to paste into.
Is there a way to call Meteor Methods from JQuery binds? Or perhaps there is a Meteor event that does this? Either will do! Thanks!
If it helps,
document.getElementById("box").value
is just a string I am passing into the 'click' method. Also, I am still working on my JQuery skills as you could probably tell.
Upvotes: 1
Views: 475
Reputation: 167
I wouldn't rely on 'input' event because as meteor docs says:
"Other DOM events are available as well, but for the events above, Meteor has taken some care to ensure that they work uniformly in all browsers."
There are also a note:
"For text fields, use blur or key events to respond to changes."
So I would code this event like this (keydown instead of input):
Template.textGoesHere.events({
'keydown #thebox': function (e) {
Meteor.call('click', e.target.value);
}
});
Also I've changed value to e.target.value because it's already inside event (you don't need to search DOM with jquery)
Upvotes: 0
Reputation: 884
Here is what did the trick:
Template.textGoesHere.events({
'input #thebox': function (e) {
Meteor.call('click', $("#thebox").val());
}
});
Every time the text area received input, even if text was removed, the Meteor function "input #thebox" is called.
This did exactly what I needed it to!
Upvotes: 1