SO - 15400775
by praveen_jegan
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/redmond/jquery-ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<input />
JavaScript
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));
}
});
function findNextDisabledDateWithinMonth(date) {
var currentDate = Number(date.split('-')[2]);
var month = $('.ui-datepicker-title>.ui-datepicker-month').text();
var year = $('.ui-datepicker-title>.ui-datepicker-year').text();
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;
}