buibr/yii2-datepicker-bs4

Bootstrap 4 date/time picker widget for Yii2

Installs: 7 420

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

v1.2 2022-05-14 17:30 UTC

This package is auto-updated.

Last update: 2024-11-12 07:46:34 UTC


README

Credits

Jonathan Peterson (@Eonasdan) for Bootstrap 4 Date/Time Picker.

Antonio Ramirez (@tonydspaniard) for inspiration by Bootstrap DatePicker Widget for Yii2 and code examples.

Installation

The preferred way to install this extension is through composer.

composer require buibr/yii2-datepicker-bs4

Usage

Please refer to the Datepicker documentation web page for options and examples of using Eonasdan's Datepicker widget.

To use widget as date/time picker, set appropriate format, e.g. 'L LT' (as in examples below). See momentjs' docs for valid formats.

With a model

use buibr\datepicker\DatePicker;

print DatePicker::widget([
    'model' => $model,
    'attribute' => 'attrName',
    'language' => 'ru',
    'size' => 'lg',
    'readonly' => true,
    'placeholder' => 'Choose date',
    'clientOptions' => [
        'format' => 'L',
        'minDate' => '2015-08-10',
        'maxDate' => '2015-09-10',
    ],
    'clientEvents' => [
        'dp.show' => new \yii\web\JsExpression("function () { console.log('It works!'); }"),
    ],
])
$config = [
    'addon' => false,
    'size' => 'sm',
    'clientOptions' => [
        'format' => 'L LT',
        'stepping' => 30,
    ],
];

print $form->field($model, 'attrName')->widget(DatePicker::className(), $config);

Without a model

use buibr\datepicker\DatePicker;

print DatePicker::widget([
    'name' => 'datepickerTest',
    'value' => '09/13/2015',
    'clientOptions' => [
        'format' => 'L',
    ],
    'dropdownItems' => [
        ['label' => 'Yesterday', 'url' => '#', 'value' => \Yii::$app->formatter->asDate('-1 day')],
        ['label' => 'Tomorrow', 'url' => '#', 'value' => \Yii::$app->formatter->asDate('+1 day')],
        ['label' => 'Some value', 'url' => '#', 'value' => 'Special value'],
    ],
])