function editDays(date) {
for (var i = 0; i < disabledDates.length; i++) {
if (new Date(disabledDates[i]).toString() == date.toString()) {
return [false]; // possible syntax error
}
}
return [true]; // AGAIN
}
First thing you need see Jquery DatePicker’s documents, and see how to use beforeShowDay function.
beforeShowDayType: Function( Date date )
Default: null
A function that takes a date as a parameter and must return an array with:
[0]: true/false indicating whether or not this date is selectable
[1]: a CSS class name to add to the date's cell or "" for the default presentation
[2]: an optional popup tooltip for this date
The function is called for each day in the datepicker before it is displayed.
Second, you need test if the code is good for Yii.
I found beforeShowDayType is not working well in Yii, so I did a little changes on that.
Here is my code, and I have tested that and it works as I wanted.
<?php echo $form->textField($model,'user_end_date');
Yii::app()->clientScript->registerScript('editDays', "
jQuery('#User_user_end_date').datepicker({
'changeYear':true,
'dateFormat':'mm/dd/yy',
//'beforeShowDay': $.datepicker.noWeekends,
'beforeShowDay': editDays,
});
function editDays(date) {
var disabledDates = ['03/31/2014', '03/13/2014', '03/19/2014'];
for (var i = 0; i < disabledDates.length; i++) {
if (new Date(disabledDates[i]).toString() == date.toString()) {
return [false,''];
}
}
return [true,''];
}
");
?>
You can see my code disabled ‘03/31/2014’, ‘03/13/2014’, ‘03/19/2014’ as I expected.