by prettyscripts on 2012-01-24 14:28:00
setting a default date value to a date picker field is not so straightforward. as in, simply set a property for the CJuiDatePicker widget.
there are 2 ways to do it. these are based on some forum posts i found a while ago.
say, default the field with today.
in the action function in controller file, prior to render a view:
PHP:
function actionSomething() { | |
.... | |
$model->date_field = date('Y-m-d'); // default to today | |
$this->render(....); | |
} |
in the view file:
PHP:
... | |
<div class="row"> | |
<?php echo $form->labelEx($model,'date_field'); ?> | |
<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array( | |
'model' => $model, | |
'attribute' => 'date_field', | |
'htmlOptions' => array( | |
'value' => date('Y-m-d'), // set the default date here | |
), | |
)) ?> | |
<?php echo $form->error($model,'date_field'); ?> | |
</div> | |
... |
note: line 8, set the default value.