https://github.com/trntv/yii2-datetime-widget
Yii2 Date/Time Widget
https://github.com/trntv/yii2-datetime-widget
Last synced: 10 months ago
JSON representation
Yii2 Date/Time Widget
- Host: GitHub
- URL: https://github.com/trntv/yii2-datetime-widget
- Owner: trntv
- Created: 2015-09-08T23:13:31.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2018-11-23T12:02:14.000Z (over 7 years ago)
- Last Synced: 2025-10-06T16:38:46.094Z (10 months ago)
- Language: PHP
- Homepage:
- Size: 13.7 KB
- Stars: 8
- Watchers: 3
- Forks: 14
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Yii2 Date/Time Picker Widget
Date/Time Picker widget for Yii2 framework
Based on [Eonasdan's Bootstrap 3 Date/Time Picker](https://github.com/Eonasdan/bootstrap-datetimepicker)

Demo
----
Since this is a part of [yii2-starter-kit](https://github.com/trntv/yii2-starter-kit) it's demo can be found in starter
kit demo [here](http://backend.yii2-starter-kit.terentev.net/article/create).
```
Login: webmaster
Password: webmaster
```
Before you start
----------------
Make sure you have [fxp/composer-asset-plugin](https://github.com/francoispluchino/composer-asset-plugin) installed:
```
composer global require fxp/composer-asset-plugin
```
Installation
------------
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require trntv/yii2-datetime-widget
```
or add
```
"trntv/yii2-datetime-widget": "*"
```
to the require section of your `composer.json` file.
## Usage
Once the extension is installed, simply use it in your code by :
```php
field($model, 'attribute')->widget(
'trntv\yii\datetime\DateTimeWidget',
[ ... options ... ]
);
?>
```
## Options
``phpDatetimeFormat`` - PHP ICU datetime format (Default: ``dd.MM.yyyy, HH:mm``)
``momentDatetimeFormat`` - Moment JS datetime format (Default: ``DD.MM.YYYY, HH:mm``)
``showAddon`` - show or hide input-addon (Default: ``true``)
``addonContent`` - addon content
``phpMomentMapping`` - formats map (Default: ``true``)
``containerOptions`` - widget container optionsgit
``clientOptions`` - [full list of available options](http://eonasdan.github.io/bootstrap-datetimepicker/Options/)
*** Note:
to enable widget show on textbox focus when used in a button group, use ``allowInputToggle`` option:
```php
...
'clientOptions' => [
'allowInputToggle' => true
]
...
```
## Examples
ActiveField input widget:
```php
field($model, 'datetime')->widget(
'trntv\yii\datetime\DateTimeWidget',
[
'phpDatetimeFormat' => 'yyyy-MM-dd\'T\'HH:mm:ssZZZZZ',
'clientOptions' => [
'minDate' => new \yii\web\JsExpression('new Date("2015-01-01")'),
'allowInputToggle' => false,
'sideBySide' => true,
'locale' => 'zh-cn',
'widgetPositioning' => [
'horizontal' => 'auto',
'vertical' => 'auto'
]
]
]
]); ?>
```
Standalone widget for date only:
```php
'yyyy-MM-dd',
]) ; ?>
```
Add custom JS events:
```php
[
'dp.change' => 'function(e){
console.log('dp.change');
}',
],
]) ; ?>
```