Yii – Add A Jquery Datepicker To A Form Field




<div class="row">

    <?php echo $form->label($model,'date'); ?>

    <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(

        'model'=>$model,

        'attribute'=>'date',

    )); ?>

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

</div>



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

and also applied the code tag */[/color]

For MySQL it is a good idea to add the date format as well (the default date format is mm/dd/yy which is not understood by MySQL):




        $this->widget('zii.widgets.jui.CJuiDatePicker', array(

            'model' => $model,

            'attribute' => 'date',

            'options' => array(

                'dateFormat' => 'yy-mm-dd',

            ),

        ));