Reputation: 35
I'm trying to use beforeShowDay
to disable and highlight days from the calendar. I found this Fiddle code that works. When I return false
it works and disables that day, but I am trying to return [false, 'holiday', '']
with a CSS class, but it's not working or not disabling dates.
function add_zero(num){
if(num<10){
return '0'+num;
}else{
return num;
}
}
$('.date').datepicker({
format: "mm-dd-yyyy",
autoclose: true,
daysOfWeekDisabled: [0],
weekStart: [1],
beforeShowDay: function(Date) {
var array = <?php echo json_encode($arry); ?>;
var curr_day = add_zero(Date.getDate());
var curr_month = add_zero(Date.getMonth() + 1);
var curr_year = Date.getFullYear();
var curr_date = curr_month + '-' + curr_day + '-' + curr_year;
for (i = 0; i < array.length; i++) {
if (curr_date == array[i]) {
// return false;
return [false, 'holiday', ''];
}
}
//return [true,''];
return true;
}
}).on('changeDate', cal_date);
Upvotes: 0
Views: 394
Reputation: 774
Mostly issue seems in your php date formats.
var highlight = ['2019/05/19', '2019/05/20'];
//tips are optional but good to have
var tips = ['some description', 'some other description'];
var disable_dates = ['2019/05/01', '2019/05/08', '2019/05/15', '2019/05/22', '2019/05/29']
$('.date').datepicker({
format: "mm-dd-yyyy",
autoclose: true,
daysOfWeekDisabled: [0],
weekStart: [1],
beforeShowDay: function (date) {
var datestring = jQuery.datepicker.formatDate('yy/mm/dd', date);
var hindex = $.inArray(datestring, highlight);
if (hindex > -1) {
return [true, 'highlight yourcustomcss', tips[hindex]];
}
var aindex = $.inArray(datestring, disable_dates);
if(aindex == -1)
return [true,'custom_enabled']
else
return [false,'custom_disabled']
}
})
Upvotes: 1