H
H
hollanditkzn2017-06-27 11:30:28
Yii
hollanditkzn, 2017-06-27 11:30:28

How to display the correct data when clicking again?

I use the dateControl kartik widget, but it turns out that when you select one datetime, when you click again, you are transferred to 12/30/1988. In the screenshot, the time frame is indicated for the first time 08/5/2017 9:00:00 AM and when you click on the widget again, it simply transfers to December 1988, although logically it should remain 08/5/2017 9:00:00 AM a06639c84442472aa88273345f05558f.png
Here is how I implemented the code in frontend / cnfig/main.php

use \kartik\datecontrol\Module;
return => [
'modules' => [
      'gridview' =>  ['class' => '\kartik\grid\Module'],
        'datecontrol' => [
            'class' => 'kartik\datecontrol\Module',
            'displaySettings' => [
            Module::FORMAT_DATE => 'dd-MM-yyyy',
            Module::FORMAT_TIME => 'hh:mm:ss a',
            Module::FORMAT_DATETIME => 'php:d M h:m',
            ],
            'saveSettings' => [
                Module::FORMAT_DATE => 'php:U',
                Module::FORMAT_TIME => 'php:H:i:s',
                Module::FORMAT_DATETIME => 'php:Y-m-d H:i:s',
            ],
            'widgetSettings' => [
                Module::FORMAT_DATE => [
                    'class' => 'yii\jui\DatePicker', // example
                    'options' => [
                        'dateFormat' => 'php:d-M-Y',
                        'options' => ['class'=>'form-control'],
                    ]
                ]
            ]
        ],
  ],
]

And in views
use kartik\datecontrol\DateControl;
<?= $form->field($model, 'srok')->widget(
                    DateControl::className(), [
                    'language' => 'ru',
                    'value' => time(),
                    'type' => DateControl::FORMAT_DATETIME,
                    'displayFormat' => 'php:d M h:m',
                    'saveFormat' => 'php:Y-m-d H:i:s',
                    'widgetOptions' => [
                        'pluginOptions' => [
                            'autoclose' => true,
                            'format' => 'dd.mm.yyyy',
                        ]
                    ]
                ])->label('Срок');?>

As I understand it, you need to specify something in value and saveFormat, but according to the documentation, I didn’t quite understand what you need to try 'saveFormat' => 'php:U', but it also doesn't work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-06-27
@hollanditkzn

Good afternoon.

'datecontrol' =>  [
            'class' => '\kartik\datecontrol\Module',
            'displaySettings' => [
                Module::FORMAT_DATE => 'd MMMM yyyy',
                Module::FORMAT_TIME => 'HH:mm',
                Module::FORMAT_DATETIME => 'd MMMM yyyy HH:mm'
            ],
            'autoWidgetSettings' => [
                Module::FORMAT_DATETIME => ['pluginOptions' => [
                                                 'autoclose' => true,
                                                 'todayHighlight' => true,
                                                 'startDate' => date('d m Y'),
                                           ],
                                           'readonly' => true],
                Module::FORMAT_DATE => ['pluginOptions' => [
                                                'autoclose' => true,
                                                'todayHighlight' => true,
                                                'startDate' => date('d m Y'),
                                       ],
                                       'readonly' => true],
                Module::FORMAT_TIME => ['readonly' => true]
            ],
            'saveSettings' => [
                Module::FORMAT_DATETIME => 'php:U',
                Module::FORMAT_DATE => 'php:U',
                Module::FORMAT_TIME => 'php:U',
            ],
            'ajaxConversion' => true,
        ]

And in the view it is enough to do this
$form->field($model, 'date_start')->widget(DateControl::className(),
                                                        ['type' => DateControl::FORMAT_DATE, 'displayTimezone' => 'Europe/Kiev']
                                                      )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question