kartik-v/yii2-detail-view

GridView edit mode, initial value

Closed this issue · 1 comments

I'm sorry, most likely this is not an issue, but I read the documentation and tried search, but wasn't able to find a solution.
So. I use DetailView in the EDIT mode to edit a model. The model has many attributes, and date is one of those. The date is stored as timestamp in the database. I use the DatePicker widget for editing the date. (basically, the below is valid for other formats as well, I took this as example only).
So the problem is when I put the date from the DB to the DatePicker widget as initial value, I can't manipulate it in any way... It just takes the raw value from the database and ignores the 'value' setting of the widget. In my example, whatever I put as 'value', it puts the timestamp into the widget.
This is my code example:

                [
                    'attribute' => 'starts',
                    'options' => ['id' => 'tournament-starts' . '-' . $model->id],
                    'type' => DetailView::INPUT_DATE,
                    'widgetOptions' => [
                        'value' => date('d.m.Y', $model->starts),
                        'removeButton' => false,
                        'pluginOptions' => [
                            'autoclose' => true,
                            'format' => 'dd.mm.yyyy',
                            'todayHighlight' => true,
                        ],
                    ],
                    'labelColOptions' => ['style' => 'width:15%'],
                    'valueColOptions' => ['style' => 'width:35%'],
                    'inputContainer' => ['class'=>'col-xs-8'],
                ],

Am I missing anything?

You will need to manipulate and convert DB Stored date formats for matching correctly for datepicker widgets.

An easier alternative is to use DateControl widget.

Check this webtip to learn how to configure date control widget with detail view.