所以我在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',
),
));
?>
但出于某种原因,它会阻止日期选择器上的所有事情。什么都不能选。那时我做错了什么?请指教。
答案 0 :(得分:1)
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'=>''
),
));
?>
现在,您需要在disableSpecificDays
标记内定义<script>
函数:
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天禁用第12天,并禁用星期一。
以下是两个有用的链接:
答案 1 :(得分:0)
我知道这是一个旧条目,但我发现对于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>
答案 2 :(得分:0)
这是一点遗留问题,但这是我通过的代码:
...
'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];
}',
...