S
S
Silverviql2018-05-17 10:19:26
Yii
Silverviql, 2018-05-17 10:19:26

How to drive the date and time in different inputs, but keep everything in one table field?

How to store time in one attribute?
With the help of this widget I enter the date.

<?= $form->field($model, 'srok')->widget(DateControl::className(),
                    [
                        'convertFormat' => true,
                        'type'=>DateControl::FORMAT_DATE,
                        'displayFormat' => 'php:d M Y',
                        'saveFormat' => 'php:Y-m-d H:i:s',

                        'widgetOptions' => [
                                'pluginOptions' => [
                                        'autoclose' => true,
                                    ],
                            'options' => ['placeholder' => 'Cрок']
                        ],
                    ])->label(false);?>

I want to make a separate time input, I took a regular text input, I
did it like this
<div class="col-xs-10">
                <?= $form->field($model, 'srok')->textInput(['maxlength' => true, 'placeholder' => 'Время', 'class' => 'inputForm'])->label(false) ?>
        </div>

But the joke is that in the input you need to enter the time in full 2018-06-08 17:00:00 and it will simply overwrite what was selected above when choosing a date. Well, you need to be able to enter, for example, 17:00, and by default, if nothing was entered, it was 13:00.
I think you can save the date and time in objects and then save it into one common one and already transfer it for saving. $datetime = $date.' '.$time
Well, add .':00' to $time, but I don't know how to implement it correctly.
I know that you can also enter the time in the DateControl widget, but there you need to select hours, then minutes, and this is a lot of clicks, and time is not so important for my task, I wanted to remove the ability to select minutes in the widget but did not find how to do it ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-05-17
@Silverviql

DateControl::FORMAT_DATE - date
DateControl::FORMAT_TIME - time
DateControl::FORMAT_DATETIME - date and time
Where did the text unput come from? As I understand it, there should be either 1 widget with DATETIME or 2: one FORMAT_DATE second FORMAT_TIME
If you need to store in one field in the database and you don’t know how to combine, then widgets have nothing to do with it. This is all done in the model in beforSave, for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question