Reputation: 706
So I initially have a datepicker which disables users to select days before the current day.
Then, I decided to add in a function, DisableMondays
which disables ALL the Mondays.
But when I add the function in, it turns out that I am then allowed to select days before. It replaces the minDate : 0
function.
The below is my code,
<script>
function DisableMonday(date) {
var day = date.getDay();
if (day == 1) {
return [false] ;
}
else {
return [true] ;
}
}
$(function() {
$( "#Booking_date" ).datepicker({
beforeShowDay: DisableMonday
});
});
</script>
<?php $form->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $model,
'attribute' => 'date',
'value' => $model->date,
'options' => array(
'showAnim'=>'fadeIn',
'showButtonPanel' => true,
'minDate'=>'0',
'changeYear' => true,
'dateFormat' => 'yy-mm-dd',
),
));
?>
Please help me with this. Thanks a lot guys.
Upvotes: 0
Views: 102
Reputation: 1109
It's simple.
You have to write 'beforeShowDay' => 'js:DisableMonday'
in options
PHP array, not in Javascript.
correct syntax is 'beforeShowDay' => 'js:DisableMonday'
<script>
function DisableMonday(date) {
var day = date.getDay();
if (day == 1) {
return [false] ;
}
else {
return [true] ;
}
}
</script>
<?php
$form->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $model,
'attribute' => 'date',
'value' => $model->date,
'options' => array(
'showAnim'=>'fadeIn',
'showButtonPanel' => true,
'minDate'=>'0',
'changeYear' => true,
'dateFormat' => 'yy-mm-dd',
'beforeShowDay' => 'js:DisableMonday',
),
));
?>
Upvotes: 2