I am using the jQuery UI datepicker as part of a booking engine allowing a user to select from only available dates.
My code is as follows:
var availableDates = ["16/06/2014", "16/06/2014", "23/06/2014", "27/06/2014", "30/06/2014", "02/07/2014", "07/07/2014", "07/07/2014", "11/07/2014", "14/07/2014", "14/07/2014", "16/07/2014", "18/07/2014", "21/07/2014", "21/07/2014", "25/07/2014", "28/07/2014", "28/07/2014", "01/08/2014", "04/08/2014", "04/08/2014", "06/08/2014", "08/08/2014", "11/08/2014", "11/08/2014", "13/08/2014", "15/08/2014", "18/08/2014", "18/08/2014", "25/08/2014", "01/09/2014", "01/09/2014", "08/09/2014", "12/09/2014", "12/09/2014"]
This code was adapted from another solution on on SO that can be found here except they are doing the opposite and excluding the items in the list. How do I adapt my code to display only the dates found in the array above?
My code example is based upon this post: Jquery UI datepicker. Disable array of Dates
$('.departureDate').datepicker({
beforeShowDay: available,
altFormat: 'yy.mm.dd',
altField: '#cultureDate'
});
function available(date) {
var dateString = jQuery.datepicker.formatDate('dd/mm/yy', date);
if(availableDates.indexOf(dateString) == -1){
console.log(dateString + " " + false);
return false;
}else{
console.log(dateString + " " + true);
return true;
}
}