Reputation: 2877
First off, the jQuery datepicker works fine with classes when doing a fresh page load. On my site however I load all the content through Ajax requests. Initially I gave each date field a unique ID and everything worked fine when loading through ajax.
(Doesnt work through Ajax)
<script type='javascript'> jQuery(function() {jQuery('.datepickerclass').datepick({dateFormat: 'yyyy-mm-dd'});});</script>
<input class='Filter datepickerclass' type="text" name="start_date" value=""/>
(Works through Ajax)
<script type='javascript'> jQuery(function() {jQuery('#start_date').datepick({dateFormat: 'yyyy-mm-dd'});});</script>
<input class='Filter date' type="text" id="start_date" name="start_date" value ="">
My best guess is that for some reason datepicker doesn't recheck the page(when using a class) when you reload part of the content and bind to new elements, but I'm not sure how to make it do this?
Upvotes: 0
Views: 4337
Reputation: 11548
Have a little try this way. see if the problem goes away (Assuming you are using the jQ UI):
$(function(){
$('.datepickerclass').on('click', function() {
$(this).datepicker({showOn:'focus'}).focus();
});
});
Or have a play along the lines of taking advantage of the live or delegate function. Hope this helps
Upvotes: 4