I am using Meteor 0.5.4 I have just encountered a strange issue with Meteor’s Session.set().
I want to show a simple modal dialogue when user clicks on a template instance.
I am using Template’s event map to set some info into Session when user clicks onto a Template instance.
Template.Orders.events({
'click' : function () {
Session.set("OrderName", this.name);
}
});
Modal dialogue template then displays the data set in Session:
Template.OrderDialogue.OrderName = function() {
return Session.get("OrderName");
}
and finally here’s my JQuery code
Template.Orders.rendered = function() {
jQuery('a[rel*=leanModal]').leanModal();
}
When I use Session.set() – as showed above inside Template.orders’s click event handler – JQuery plugin doesn’t show the modal dialogue on the first click on the template instance but only on second click on that exact instance. It takes two clicks on template instance to get the modal dialogue.
When I remove Session.set() everything is working fine – modal dialogue is shown on first click as it’s supposed to work.
Debug output shows that Session value is properly set on the first click.
How can Session.set() interfere with my JQuery plugin?
leanModalis showing the HTML content ofOrderDialoguebefore the Meteor engine reactively infuses the new content into it, so the key is to wrap theleanModalclick in asetTimeoutto ensure the reactivity has happened.Assuming you have:
And your javascript:
Then you have to hack the leanmodal widget with a
setTimeouton the click event handler, to give the reactivity a moment to render theOrderNamecontent prior to event bubbling.Assuming this is the script, wrap the click handler in this script (starting around line 23) like this: