Template.tpl.helpers
day:-> if $('select').val()=='day' then true
night:-> if $('select').val()=='night' then true
Template.tpl.onRendered ->
$('.ui.popup').popup()
This code $('.ui.popup').popup() initializes popups on respective elements (semantic-ui).The problem is that itâs ran only once on tpl render thus affecting only this node: <div class='ui popup' data-popup='I'm awake!'>day</div>.
When I choose night this code $('.ui.popup').popup() is not run leaving newly rendered node <div class='ui popup' data-popup='I'm asleep'>night</div> without popup.
Moreover, when I select day back again - it doesnât have popup this time! As it has invoked rendering of entirely new âdayâ div, and not the old one.
What can be done here?
Weird, it works here (after translating to javascript).
Template.tpl.helpers({
day: function(){
var day = Template.instance().daySelected.get();
return day == 'day';
},
night: function() {
var day = Template.instance().daySelected.get();
return day == 'night';
},
});
In my pad everythingâs been corrected and the helpers are working fine: you can see that initially if you hover over day, the popup is there and after you change select, âdayâ changes to ânightâ as expected.
Thing is - $('.ui.popup').popup() isnât getting called again on the newly rendered span element!
Template.tpl.onRendered(function(){
this.autorun(function(){
var day = Template.instance().daySelected.get(); // reactivity
Tracker.afterFlush(function(){ // wait for rendering to be done
$('.time').popup().each(function(){console.log(this)});
});
});
});
Whoa! Thanks, mate! Youâve just saved me lots of repeating lines of code if I went for wrapping each day\night component (of which I have dozens) into a separate template - phewâŚ
Now I just need to sort out how this Tracker stuff worksâŚ)
Iâve updated my pad for those facing same issues.
@jamgold, kudos once again @lai, thank you too, man