-1

Before it was really easy to disable a specific date with the option disable:

$('.datepicker').pickadate({
  disable: [
    new Date(2015,3,13),
    new Date(2015,3,29)
  ]
})

But now It only has an option called disableDayFn which as far as I know, works something like this:

disableDayFn: function(date) {
   return date.getDay() == 1 || date == new Date(2018, 26, 5); //Not working
},

The part about getDay disables every first day on the datepicker (sunday or monday or whichever you have configured) but I haven't been able to disable a specific date, I also tried using getDate() but it disables a specific day number on every month, not an specific one. I've been trying for hours to figure it out.

coder
  • 8,346
  • 16
  • 39
  • 53
  • Using `==` to compare two `Date` objects could be the problem. Please try the solution of [this](https://stackoverflow.com/questions/4428327/checking-if-two-dates-have-the-same-date-info) question. – ikkuh May 06 '18 at 09:26
  • Shouldn't it be `new Date(2018, 5, 26)` instead of `new Date(2018, 26, 5)`? – Munim Munna Jul 05 '18 at 18:33

2 Answers2

1

Well I ended up experimenting more and resolving this by myself, if anyone else has the same problem my solution was this:

var disabledDays = ['2018-05-06', '2018-05-18'];

var pickADate = M.Datepicker.init(elem, {
  disableDayFn: function(date) {
    var dateParsed = date.toISOString().split("T")[0];
    return (
      date.getDay() == 1 ||  //This disables first day of the week
      date.getDay() == 4 ||  //This disables fourth day of the week
      disabledDays.indexOf(dateParsed) > -1 //This checks if the date is in disabledDays
    );
  }
});
rubenscd
  • 23
  • 3
0

I was able to get this to work by converting the date to string for the comparison like below:

disableDayFn: (date) => {
    return date.toString() == (new Date(2018, 6, 9)).toString() || date.toString() == (new Date(2018, 6, 19)).toString();
}
Munim Munna
  • 17,178
  • 6
  • 29
  • 58
Jaycen
  • 1
  • 1