So I have this widget on my Yii _form.php
page.
Is it possible to do things like blocking a certain day of the month? Or maybe blocking all the Mondays of the Month, disallowing users to select any Monday.
UPDATES based on hamed's answer
<script type="text/javascript">
function disableSpecificDays(date) {
//date is an instance of Date
var weekDay = date.getDay(); // Get the weekday as a number (0-6)
if(weekDay == 1){ //weekDay == 1 means Monday
return false;
}
else {
return true;
}
}
</script>
And on the view side,
<?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' => 'disableSpecificDays',
),
));
?>
But for some reason, it blocks EVERYTHING on the date picker. Nothing can be chosen at all. At which point did I do wrong? Please advise.
jqueryUi datepicker has beforeShowDay
event. You can use this event in this way:
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
...
'options'=>array(
'showAnim'=>'slide',//'slide','fold','slideDown','fadeIn','blind','bounce','clip','drop'
'showOtherMonths'=>true,// Show Other month in jquery
'selectOtherMonths'=>true,// Select Other month in jquery,
'beforeShowDay' => 'disableSpecificDays', //changed ':' to '=>' AND added quote in between function name.
),
'htmlOptions'=>array(
'style'=>''
),
));
?>
Now, you need to define disableSpecificDays
function inside <script>
tag:
function disableSpecificDays(date) {
//date is an instance of Date
var weekDay = date.getDay(); // Get the weekday as a number (0-6)
var monthDay = date.getDate() //Get the day as a number (1-31)
if(monthDay == 12 || monthDay == 13 || weekDay == 1) //weekDay == 1 means Monday
return false;
else return true;
}
This will disable 12th an 13th days in each month and also disable Mondays.
Here are the two useful link: