I am trying to set up flatpickr to disable certain dates based on a csv file AND disable certain days of the week. I am not able to get both working at the same time, only one or the other.
My code so far:
$(document).ready(function () {
var csvurl = "dates.csv";
$.ajax({
type: "GET",
async: false,
url: csvurl,
dataType: "text",
success: function (data) {
var csvArray = $.csv.toArrays(data);
fCsvArray(csvArray);
}
});
function fCsvArray(csvArray) {
var daysArray = [];
for (var i = 0; i < csvArray.length; i++) {
var newItem = csvArray[i];
daysArray.push(csvArray[i][0]);
}
console.log("daysArray = " + daysArray);
flatpickr.localize(flatpickr.l10ns.ja);
$("#nkibo-date1").flatpickr({
disable: [
function (date) {
return (date.getDay() === 0 || date.getDay() === 1 || date.getDay() === 2 || date.getDay() === 6);
}
],
//disable: daysArray,
locale: {
firstDayOfWeek: 1
},
disableMobile: true,
minDate: new Date().fp_incr(7),
dateFormat: "Y/m/d"
});
}
});
If I comment out the first "disable" function and run the script with the second "disable" code, that part works too but I would like them to work together. I have read that using the Enable and Disable options together is not possible, since I tried to enable the days that are available, then adding the Disabled dates afterwards, as a workaround.
The dates are as follows (in case anyone needs them):
2022/10/06
2022/10/07
2022/10/12
2022/11/23
2022/12/07
2022/12/08