jquery-uiyiijquery-ui-datepickerzii-widgetsyii-widgets

How to put default value in CJuidatepicker in Yii?


I have the code below to display a calendar input in Yii form.

<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                'name' => 'publish_date',
                'attribute' => 'publish_date',
                'model'=>$model,
                'options'=> array(
                  'dateFormat' =>'yy-mm-dd',
                  'defaultDate' => '2014-3-4',
                  'altFormat' =>'yy-mm-dd',
                  'changeMonth' => true,
                  'changeYear' => true,
                  'appendText' => 'yyyy-mm-dd',
                ),  
              )); 
 ?>

The default value work on the calendar but I want to show it by default in the calendar input too when the form is rendering.

How can I do it?


Solution

  • You can use Html value attribute for this

    <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                    'name' => 'publish_date',
                    'attribute' => 'publish_date',
                    'model'=>$model,
                    'options'=> array(
                      'dateFormat' =>'yy-mm-dd',
                      'defaultDate' => '2014-3-4',
                      'altFormat' =>'yy-mm-dd',
                      'changeMonth' => true,
                      'changeYear' => true,
                      'appendText' => 'yyyy-mm-dd',
                    ),
                   'htmlOptions'=>array('value'=>'2013-4-4')
                  ));