Search code examples
eonasdan-datetimepicker

Tried 7 times to find a valid date


I'm trying to invoke a calendar with every day blocked excepting Thursdays.

Some Thursdays will be blocked, so I use daysOfWeekDisabled and disableDate.

jQuery('.custom-calendar-2').datetimepicker({
    format: "dd/mm/yyyy",
    daysOfWeekDisabled: [0,1,2,3,5,6],
    useCurrent: true,
    inline: true,
    /*beforeShowMonth: function (date) {
        if (date.getMonth() == 8) {
            return false;
        }
    },*/
    defaultDate: null,
    minDate: moment().add(1, 'days'),
    disabledDates: [
        moment('04/07/2016', 'MM/DD/YYYY'),
        moment('04/21/2016', 'MM/DD/YYYY')
    ],
    //toggleActive: true
});

If I comment the line

moment('04/07/2016', 'MM/DD/YYYY'),

my calendar works. I'm trying to debug this but I just don't get it. The console says:

Tried 7 times to find a valid date

How I can solve that error?

EDIT:

I've digged into the library. On line 1648 there is this snippet:

if (tries === 7) {
    throw 'Tried 7 times to find a valid date';
}

Changing the number of tries to something bigger like 14 just does the work. I get the idea of avoid some kind of infinite loop, but this way you can't do a basic operation like blocking the current week.

I wonder if there is another better way that modifying the library myself/monkey patching. Or this should be directly patched into the repository?


Solution

  • I've sent a pull request for a temporal fix. https://github.com/Eonasdan/bootstrap-datetimepicker/pull/1558