Problem config "dateTimePicker" on template rendered (want to run after view is ready)?


#1

I have problem with any config like dateTimePicker on template rendered

updateTpl.onRendered(function () {
   var dob = $('[name="dob"]');
   dob................// config;
});

It don’t work.
and then I tried config on browser console, It work fine.
Please help me.


#2

try this pattern

Tracker.afterflush(function(){
  // jquery initialization
})

But if those pickers depend on subscribed data, you should put all these within the subscription callback.


#3

Have you try this?

   $('[name="dob"]').dateTimePicker({
            locale: 'ru'
   });

#4

Thanks for your helping.
I will try format: 'Tracker.afterflush, but where in rendered or out.
Could I check the view is ready?


#5

If you don’t need data to be ready, you can do

updateTpl.onRendered(function () {
  Tracker.afterFlush({
    var dob = $('[name="dob"]');
     dob................// config;
  }) 
});

But if you also need the data, you can set up a template level subscription within onCreated

updateTpl.onCreated(function () {
  var template = this;
  // first subscribe
  template.subscribe('dobDataPublication', function() {
    // wait for the subsciption to be ready
    Tracker.afterFlush({
      // wait for the data to be rendered and template flush cycle get completed
      var dob = $('[name="dob"]');
       dob................// config;
    }) 
  })
});

#6

Thanks again.
So it mean that Tracker is run after the view is ready for all (onCreated, onRendered).


#7

No.

Tracker is Meteor’s client side dependency tracking system.

afterFlush represents the end of a cyle of batched reactive updates.

The docs should give you a clearer picture.