Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a twitter bootstrap datepicker to work with Meteor?

I would rather use the Meteor package implementation of Bootstrap rather than the less files version but I am having a hell of a time getting a datepicker to work.

There seem to be three versions in varying states with the last one by Aymkdn being compiled and ready to go.

http://www.eyecon.ro/bootstrap-datepicker/

https://github.com/eternicode/bootstrap-datepicker/

https://github.com/Aymkdn/Datepicker-for-Bootstrap

The version by Aymkdn works fine in plain vanilla html but not served from Meteor and I am having a helluva time figuring out why.

I would like to use the one by Aymkdn with Meteor but I cannot get it to work. I think it may have to do with either the js loading order in Meteor or the DOM rendering. Any insights into how I can get this to work?

Thanks Steeve

like image 376
Steeve Cannon Avatar asked Aug 13 '12 10:08

Steeve Cannon


1 Answers

Perhaps this approach wasn't available when this question was originally posted, but I'm initializing the datepicker when its template is rendered.

Template.templateName.rendered = function() {
    $('#datepicker').datepicker();
}

Here is a link to the event: http://docs.meteor.com/#template_rendered

With this approach, I don't have maintain a session property or handle focus events. Prashant's solution didn't work for me when the template was unloaded and returned to since the session property was tripped. I also had an issue wherein the datapicker didn't display the first time it got focus.

Yes, the datapicker will get initialized each time the template is rendered, but I think that's okay since I'm pretty sure template resources are cleaned up when navigating between them anyway.

like image 80
Don Smith Avatar answered Sep 28 '22 08:09

Don Smith