Yii – Add A Jquery Datepicker From And To Date

Yii – Add A Jquery Datepicker From and To date disable before dates from_date in To_date field

Here is the code

<div class="row">

        <?php echo $form->labelEx($model,'from_date'); ?>

        <?php echo $form->textField($model,'from_date'); ?>

        <?php echo $form->error($model,'from_date'); ?>


<div class="row">

        <?php echo $form->labelEx($model,'to_date'); ?>

        <?php echo $form->textField($model,'to_date'); ?>

        <?php echo $form->error($model,'to_date'); ?>



        jQuery(function() {

                var dates = jQuery( "#<?php echo CHtml::activeID($model, 'from_date')?>, #<?php echo CHtml::activeID($model, 'to_date')?>" ).datepicker({

                        defaultDate: "+1w",

                        dateFormat: "yy-mm-dd",

                        changeMonth: true,

                        numberOfMonths: 1,

                        onSelect: function( selectedDate ) {

                                var option = this.id == "<?php echo CHtml::activeID($model, 'from_date')?>" ? "minDate" : "maxDate",

                                        instance = jQuery( this ).data( "datepicker" ),

                                        date = jQuery.datepicker.parseDate(

                                                instance.settings.dateFormat ||


                                                selectedDate, instance.settings );

                                dates.not( this ).datepicker( "option", option, date );





[color="#556B2F"]/* Moved from "General Discussion for Yii 1.1.x" to "Tips, Snippets and Tutorials" …

and also applied the proper mark ups */ [/color]