Preselected values ​​in DateControl yii 2

I have the following code:

$form->field($model, 'start_time')->widget(DateControl::classname(), [
                    'type'=>DateControl::FORMAT_DATETIME,
                    'displayFormat' => 'php:d-M-Y H:i:s',
                    'ajaxConversion'=>true,
                    'options' => [
                        'pluginOptions' => [
                            'autoclose' => true
                        ]
                    ]
                ]);

      

works great. we can select the date and time and send the data to the controller to save it.

Problem

When I write this same code in the update form, the values ​​that come from the database are not shown in the datecontrol field. Its empty .. I tried to provide a unix type date and time and a regular string (24-Jul-2015), but that doesn't show anything. Does anyone know how to do this?

other fields like the following seem to work fine and populate with values ​​from the database

<?= $form->field($model, 'price')->textInput() ?>

      

+3


source to share


1 answer


I found kartik's answer.

just add



saveFormat=>'d-M-y'

      

under displayFormat

or any other format of your choice and it will display the stored value .. just :)

0


source







All Articles