I have an array of dates pulled from a database that I am trying to disable on the datepicker. The array below is the results from my database. Using Jquery UI datepicker. Disable array of Dates as guidance, I tried to disable the dates from my array. My page is connected to
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
and my own .js file.
From my HTML page:
<input id="resDate">
From my JavaScript file:
$(document).ready(function () {
blackoutDates();
});
function blackoutDates() {
var unavailableDates = ["10/27/2018", "11/8/2018", "4/25/2018"]
$(function () {
$("#resDate").datepicker({
todayHighlight: true,
beforeShowDay: function (date) {
var string = jQuery.datepicker.formatDate('mm-dd-yy', date);
return [unavailableDates.indexOf(string) == -1]
}
});
});
}
On JSFiddle the result is that the dates are completely unaffected (i.e. none are disabled). On my page, I received the error "Uncaught TypeError: Cannot read property 'formatDate' of undefined". Since that function did not work, I also tried:
$(document).ready(function () {
blackoutDates();
});
function blackoutDates() {
var unavailableDates = ["10/27/2018", "11/8/2018", "4/25/2018"]
$(function () {
$("#resDate").datepicker({
todayHighlight: true,
beforeShowDay: function unavailable(date) {
dmy = date.getDate() + "/" + (date.getMonth() + 1) + "/" +
date.getFullYear();
if ($.inArray(dmy, unavailableDates) == -1) {
return [true, "","Available"];
} else {
return [false, "", "Unavailable"];
}
}
});
});
}
This did not disable any dates on both my page and JSFiddle. When I step through it while debugging with Chrome, the loop breaks after May 5,2018. Maybe it is having issues because it did not reach all of my array dates?
I have really confused myself. All advice is appreciated! Thank you!