amsul / pickadate.js

The mobile-friendly, responsive, and lightweight jQuery date & time input picker.
http://amsul.ca/pickadate.js
MIT License
7.7k stars 1.01k forks source link

Current date following up #1164

Closed bsgies closed 5 years ago

bsgies commented 5 years ago

Hi,

If you notice that if today is 7th of May then the calendar will highlight today's date. But if you move to the next or previous month it keeps highlighting the 7th of every month too. How do I only highlight today's date and not every 7th?

DanielRuf commented 5 years ago

Hi @bsgies,

could you find a solution? If so please post the answer so others know it too.

bsgies commented 5 years ago

I ran into this issue as well. As a workaround, I remove the picker__day--highlighted class from every div with that class that doesn't have today's timestamp as data-pick value:

var now = new Date();
var timestamp = new Date(now.getFullYear(), now.getMonth(), now.getDate()) / 1;

$('.datepicker').pickadate({
onRender: function() {
    $('div.picker__day--highlighted').each(function(index, value) {
        if ($(this).data('pick') !== timestamp) {
            $(this).removeClass('picker__day--highlighted');
        }
    });
}
});