Yii,CJuiDatePicker如何阻止某个月的某些天

fnatzsnv  于 2022-11-09  发布在  其他
关注(0)|答案(3)|浏览(160)

所以我在Yii _form.php页面上有这个小部件。
有没有可能做一些事情,比如阻止一个月中的某一天?或者阻止一个月中的所有星期一,不允许用户选择任何星期一。

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

但由于某种原因,它挡住了日期选择器上的所有东西。根本什么都选不到。我在哪一点上做错了?请指教。

omvjsjqw

omvjsjqw1#

jqueryUi datepicker有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日,同时禁用星期一。
下面是两个有用的链接:

dgiusagp

dgiusagp2#

我知道这是一个旧的条目,但是我发现对于Yii 1,把返回值放在括号[]中就可以了。所以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>
jum4pzuy

jum4pzuy3#

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

...
'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];
        }',
...

相关问题