nazar-pc / PickMeUp

Really simple, powerful, customizable and lightweight standalone datepicker
BSD Zero Clause License
615 stars 191 forks source link

Render weekend days and holiday days #146

Closed pararrayos closed 7 years ago

pararrayos commented 7 years ago

Hi Mr. Mokrynskyi. I'm using your fabolous calendar and I'm facing a minor problem.

I'm using render to make weekend days un-selectables, so I'm coding this:

...
render : function (date) {
        if (date.getDay() % 6 == 0) {
            return {disabled : true};
        }
               return {};
            }
...

Note: three dots just mean more code before and after

This works fine. But now I want to make holidays days un-selectables too, so I'm trying with this:

var holidayArray = [
        new Date('whateverday').getTime(), 
        new Date('whateverday').getTime(), 
       etc...]
...
render : function (date) {
        if (date.getDay() % 6 == 0) {
            return {disabled : true};
        }
        for (var h = 0; h < holidayArray.length; h++) {
            if (holidayArray[h] == date.getTime()) {
                return {disabled : true};
            }
        } 
        return {};
       }
...

And now weekend days are still unselectables (as desired) but holiday days' piece of code isn't working. Is there any 'restriction' or something like that in using a for loop inside render?

Thanks :)

nazar-pc commented 7 years ago

There is no such limitation, any function is allowed there. Try to use debugger in Dev Tools, just put breakpoint on the line inside of the loop to see if it is working and if not, then why. You can also run it line by line and see what exactly values are compared.

pararrayos commented 7 years ago

I found it. There was a missmatch among new Date('whateverday').getTime() and date.getTime(). Now it works. Thank you anyway.