AFIK, there is no official resource for finding out the disabled dates in jQuery Datepicker.
However jQuery UI Datepicker is a library upon Javascript, there is always a workaround. Below is a workaround I have tried.
Step #1:
Below is a way to disable a list of dates in jQuery Datepicker.
var array = ["2014-03-14", "2014-03-18", "2014-03-16", "2014-04-01"]
$('input').datepicker({
dateFormat: 'yy-mm-dd',
beforeShowDay: function (date) {
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [array.indexOf(string) == -1]
},
onSelect: function (date) {
console.log(findNextDisabledDateWithinMonth(date));
}
});
Now here my approach to get the next disabled date within the month.
Step #2:
function findNextDisabledDateWithinMonth(date) {
var currentDate = Number(date.split('-')[2]);
var month = $('.ui-datepicker-title>.ui-datepicker-month').text(); //Number(date.split('-')[1])
var year = $('.ui-datepicker-title>.ui-datepicker-year').text(); //Number(date.split('-')[0])
var nextConsectiveDates = [];
$.each($('.ui-state-disabled').find('.ui-state-default'), function (i, value) {
var numericDate = +$(value).text();
if (currentDate < numericDate) {
nextConsectiveDates.push(numericDate);
}
});
var nextDisabledDate = nextConsectiveDates[0] + "-" + month + "-" + year;
return nextDisabledDate;
}
JSFiddle
NOTE: This is work only for the selected date's month
Approach #2
As @ Salman A mentioned in his comment, I feel the best way is to go with it. Since my approach will is constrained within month.
Here is an elegant approach to solve your problem.
var array = ["2014-05-01", "2014-04-14", "2014-04-18", "2014-04-16"];
// Convert all those string dates into Date array
var arrayAsDateObjects = convertStringToDateObject(array);
$('input').datepicker({
dateFormat: 'yy-mm-dd',
beforeShowDay: function (date) {
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [array.indexOf(string) == -1]
},
onSelect: function (date) {
alert(findNextDisabledDateWithinMonth(date).toDateString());
}
});
//To find the next exact disabled date based on the selected date
function findNextDisabledDateWithinMonth(date) {
var splitDate = date.split("-");
var selectedDate = new Date(splitDate[0], Number(splitDate[1]) - 1, splitDate[2]);
var nextDisabledDate = null;
$.each(arrayAsDateObjects, function (i, ele) {
if (selectedDate < ele) {
nextDisabledDate = ele;
return false;
} else {
nextDisabledDate = "No Disabled dates available";
}
});
return nextDisabledDate;
}
//convert all the string dates to Date object
function convertStringToDateObject(array) {
var ls = [];
$.each(array, function (i, ele) {
var splitDate = ele.split("-");
var date = new Date(splitDate[0], Number(splitDate[1]) - 1, splitDate[2]);
ls.push(date);
});
// Sort the dates in ascending order(https://stackoverflow.com/a/10124053/1671639)
ls.sort(function (a, b) {
return a - b;
});
return ls;
}
for sorting dates, I took reference from @Phrogz 's answer