Skip to content

alexantr/yii2-datetimepicker

Repository files navigation

Datetime picker input widget for Yii 2

This extension renders an input with flatpickr.

Latest Stable Version Total Downloads License

Installation

Install extension through composer:

composer require alexantr/yii2-datetimepicker

Usage

The following code in a view file would render an input with color picker:

<?= alexantr\datetimepicker\DateTimePicker::widget(['name' => 'attributeName']) ?>

If you want to use this input widget in an ActiveForm, it can be done like this:

<?= $form->field($model, 'attributeName')->widget(alexantr\datetimepicker\DateTimePicker::className()) ?>

Configuring the flatpickr options should be done using the clientOptions attribute:

<?= alexantr\datetimepicker\DateTimePicker::widget([
    'name' => 'attributeName',
    'clientOptions' => [
        'allowInput' => false,
        'enableTime' => false,
        'enableSeconds' => false,
        'dateFormat' => 'Y-m-d',
    ],
]) ?>

By default widget uses flatpickr's options:

[
    'allowInput' => true,
    'dateFormat' => 'Y-m-d H:i:S',
    'enableTime' => true,
    'enableSeconds' => true,
    'minuteIncrement' => 1,
    'time_24hr' => true,
]