Yii, CJuiDatePicker 如何屏蔽一个月中的某些日子

Yii, CJuiDatePicker how to block certain days of the Month

所以我的 Yii _form.php 页面上有这个小部件。

是否可以做一些事情,比如屏蔽一个月中的某一天?或者可能会阻止该月的所有星期一,不允许用户在任何星期一 select。

根据 hamed 的回答更新

<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>

在视图方面,

<?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',
        ),              
    ));
?>

但出于某种原因,它会阻止日期选择器上的所有内容。什么都不能选择。我在哪一点上做错了?请指教

jqueryUi 日期选择器有 beforeShowDay 事件。您可以这样使用此事件:

$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'=>''
  ),
));
?>

现在,您需要在 <script> 标签内定义 disableSpecificDays 函数:

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;
}

这将禁用每个月的第 12 天和第 13 天,还会禁用星期一。

这里有两个有用的link:

我知道这是一个旧条目,但我发现对于 Yii 1,将 return 值放在方括号 [] 中就可以了。所以JS函数应该是:

<script type="text/javascript">
    //DON'T SHOW SUNDAYS
    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();
        if(weekDay == 0){
            return [false];
        }
        else {
            return [true];
        }
    }
</script>

这是一个遗留问题,但这是我通过的代码:

...
'options'=>array(
    'beforeShowDay'=> 'js:function(date){ 
        var weekDay = date.getDay(); 
        var monthDay = date.getDate()  
        if(monthDay == 27 || weekDay == 1) { //Disable all Mondays & 27th of the each month
            return [false];
        } else { 
            return [true];
        }',
...