yii2-widget-timepicker in Activeform
- By Preneesh AV --
- 05-Sep-2018 --
- 68 Comments
The TimePicker widget allows you to easily select a time for a text input using your mouse or keyboards arrow keys.
Installation
The preferred way to install this extension is through composer. Check the composer.json for this extension's requirements and dependencies. Read this web tip /wiki on setting the minimum-stability settings for your application's composer.json.
To install, either run
$ php composer.phar require kartik-v/yii2-widget-timepicker "*"or add
"kartik-v/yii2-widget-timepicker": "*"to the require section of your composer.json file.
View file:
<div class="form-group">
<?php echo $form->field($data, 'EventStartTime')->widget(TimePicker::classname(), [
'options' => ['value' => isset($data->EventStartTime) ? date('h:i a', strtotime($data->EventStartTime)) : null,],
])->label(false); ?>
</div>
Controller before saving data:
$data->EventStartTime = date('Y-m-d H:i:s', strtotime($data->EventStartTime));
