<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
'name'=>'Settings[start_date]',
'value'=>date("d-m-Y",strtotime($model->start_date)),
'options'=>array(
//'buttonImage'=>Yii::app()->theme->getBaseUrl().'/img/calendar.png',
//'buttomImageOnly'=>true,
//'showOn'=>'button',
'changeMonth'=> true,
'changeYear'=> true,
'showAnim'=>'fold',
'dateFormat' => 'dd-mm-yy',
),
'htmlOptions'=>array(
'id'=>'start_date',
),
));
?>
<?php echo $form->error($model,'start_date'); ?>
</div></div></td>
<td style="width:516px"><div class="formItem leftLabel"><label for="end_date" class="required">End Date </label><div class="formInputBox" style="width:210px;">
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
'name'=>'Settings[end_date]',
'value'=>date("d-m-Y",strtotime($model->end_date)),
'options'=>array(
//'buttonImage'=>Yii::app()->theme->getBaseUrl().'/img/calendar.png',
//'buttomImageOnly'=>true,
//'showOn'=>'button',
'changeMonth'=> true,
'changeYear'=> true,
'showAnim'=>'fold',
'dateFormat' => 'dd-mm-yy',
),
'htmlOptions'=>array(
'id'=>'end_date',
),
));
?>
<?php echo $form->error($model,'end_date'); ?>
我想在end_date字段中限制日期,该日期不应低于start_date中的日期,例如。如果在start_date中选择的日期是01-06-2014,则允许用户在01-06-2014之后选择日期,不低于01-06-2014 如何在end_date字段中限制日期选择?
答案 0 :(得分:1)
使用jquery的简单方法。
<script>
$('#start_date').change(function(){
var start_date = $(this).val();
$("#end_date").datepicker( "option","minDate",start_date);
});
$('#end_date').change(function(){
var end_date = $(this).val();
$("#start_date").datepicker( "option","maxDate",end_date);
});
</script>
还使用CJuiDatePicker
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
'model' => $model,
'attribute'=>'start_date',
'options'=>array(
'changeMonth'=> true,
'changeYear'=> true,
'showAnim'=>'fold',
'dateFormat' => 'dd-mm-yy',
'onSelect' => 'js:function( selectedDate ) {
$( "#' . CHtml::activeId($model, 'end_date') . '" ).datepicker("option", "minDate", selectedDate);
}'
),
'htmlOptions'=>array(
'id'=>'start_date',
),
));
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
'model' => $model,
'attribute'=>'end_date',
'options'=>array(
'changeMonth'=> true,
'changeYear'=> true,
'showAnim'=>'fold',
'dateFormat' => 'dd-mm-yy',
),
'htmlOptions'=>array(
'id'=>'end_date',
),
));