w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
cjuidatepicker restrict dates in second date field based on selected date in first date field yii

Simple Method using 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>

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




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.