https://github.com/cgsmith/yii2-flatpickr-widget
https://github.com/cgsmith/yii2-flatpickr-widget
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/cgsmith/yii2-flatpickr-widget
- Owner: cgsmith
- License: bsd-3-clause
- Created: 2022-12-06T00:37:56.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-09-25T08:18:18.000Z (almost 2 years ago)
- Last Synced: 2025-10-04T06:57:32.261Z (10 months ago)
- Language: PHP
- Size: 14.6 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
Flatpickr JS Widget for Yii2
====================================
[](https://packagist.org/packages/cgsmith/yii2-flatpickr-widget)
[](https://packagist.org/packages/cgsmith/yii2-flatpickr-widget)
[](https://packagist.org/packages/cgsmith/yii2-flatpickr-widget)
[](https://packagist.org/packages/cgsmith/yii2-flatpickr-widget)
Renders a [flatpickr Datepicker plugin](https://flatpickr.js.org/).
Installation
------------
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```bash
$ composer require cgsmith/yii2-flatpickr-widget:~1.1
```
or add
```json
"cgsmith/yii2-flatpickr-widget": "~1.1"
```
to the require section of your application's `composer.json` file.
Usage
-----
The widget renders the flatpickr onto your form.
***Example of use with a form***
Use the widget by setting up its `model` and `attribute`.
```php
= FlatpickrWidget::widget([
'model' => $model,
'attribute' => 'date',
]);?>
field($model, 'date')->widget(
FlatpickrWidget::widget([
'model' => $model,
'attribute' => 'date',
'flatpickrConfig' => [ // This is passed as a JSON object to flatpickr
'enableTime' => false,
'dateFormat' => 'F j, Y H:i',
'altInput' => true,
'altFormat' => 'F j, Y',
'locale' => 'ru', // optional
]
]);
?>
```
#### Example
> It's not a demo without a GIF

***Example of use on Gridview***
You may need to adjust the filter to work with your form or search model but this is how it is working with a default
Yii installation.
```php
$dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'created_at',
'label' => 'Created At',
'format' => 'datetime',
'value' => 'created_at',
'filter' => \cgsmith\flatpickr\FlatpickrWidget::widget(
[
'model' => $searchModel,
'attribute' => 'created_at',
'flatpickrConfig' => [
'enableTime' => false,
'dateFormat' => 'U',
'altInput' => true,
'altFormat' => 'F j, Y',
],
]
)
],
'updated_at:datetime',
// other columns and settings for gridview
],
]);
```
Resources Information
-------------------
Please, check the [flatpicker site](https://flatpickr.js.org/options/) documentation for further information about its configuration options.
Contributing
------------
Contributions are welcome!
Credits
-------
- [Chris Smith](https://github.com/cgsmith)
- [All Contributors](../../contributors)
License
-------
The BSD License (BSD). Please see [License File](LICENSE.md) for more information.