Date/Time Picker widget for Yii2 framework Based on Eonasdan's Bootstrap 3 Date/Time Picker

Overview

Yii2 Date/Time Picker Widget

Date/Time Picker widget for Yii2 framework Based on Eonasdan's Bootstrap 3 Date/Time Picker DateTimePicker

Demo

Since this is a part of yii2-starter-kit it's demo can be found in starter kit demo here.

Login: webmaster
Password: webmaster

Before you start

Make sure you have fxp/composer-asset-plugin installed:

composer global require fxp/composer-asset-plugin

Installation

The preferred way to install this extension is through composer.

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 :

 echo $form->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

*** Note: to enable widget show on textbox focus when used in a button group, use allowInputToggle option:

...
'clientOptions' => [
    'allowInputToggle' => true
]
...

Examples

ActiveField input widget:

false, 'sideBySide' => true, 'locale' => 'zh-cn', 'widgetPositioning' => [ 'horizontal' => 'auto', 'vertical' => 'auto' ] ] ] ]); ?>">
 echo $form->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:

 echo trntv\yii\datetime\DateTimeWidget::widget([
    'phpDatetimeFormat' => 'yyyy-MM-dd',
]) ; ?>

Add custom JS events:

 echo trntv\yii\datetime\DateTimeWidget::widget([
    'clientEvents' => [
        'dp.change' => 'function(e){
            console.log('dp.change');
        }',
    ],
]) ; ?>
Comments
  • Output 1970-01-01 00:00:00 on Empty String

    Output 1970-01-01 00:00:00 on Empty String

    When the form is submitted with empty string it will generate 1970-01-01 00:00:00 is this expected behaviour?

    as I don't like it, I do a quick fix by changing line 104 to if ($value !== null && $value !== '') {

    opened by shyevsa 1
  • Invalid Parameter – yii\base\InvalidParamException

    Invalid Parameter – yii\base\InvalidParamException

    Hi, I got the error:

    The file or directory to be published does not exist: vendor/bower/eonasdan-bootstrap-datetimepicker

    i replace this

    public $sourcePath = '@bower/eonasdan-bootstrap-datetimepicker';
    public $sourcePath = '@bower/moment';
    

    for this

    public $sourcePath = '@bower/bower-asset/eonasdan-bootstrap-datetimepicker';
    public $sourcePath = '@bower/bower-asset/moment';
    
    opened by gugoan 1
  • Exception Thrown when KeepInvalid is set a true

    Exception Thrown when KeepInvalid is set a true

    When we have KeepInvalid option set as true and we submit a not supported date (ex 2018-10-10 10) we get an Exception thrown.

    The problem happens here when call Yii::$app->formatter->asDatetime("2018-10-10 10") to a wrong date

     $this->options['value'] = array_key_exists('value', $this->options)
                    ? $this->options['value']
                 : Yii::$app->formatter->asDatetime($value, $this->phpDatetimeFormat);
    }
    
    opened by k3bra 1
  • Not work if two datetimepicker in modal bootstrap.

    Not work if two datetimepicker in modal bootstrap.

    Dear trntv,

    if i have 2 datetimepicker, the first is success, but the second have an error like this : Uncaught Error: Could not initialize DateTimePicker without an input element at c (:2:2239) at HTMLButtonElement.

    opened by ahmadfadlydziljalal 1
  • timezone problem

    timezone problem

    My $model->date_s = 2017-03-06 19:00:00

    But the input field default is 2017-03-06T20:00:00+0100

    if in phpDatetimeFormat i insert eg yyyy-MM-DD HH:mm:ss i've error because is not in your protected $defaultPhpMomentMapping

    this is the config ` $form->field($model_post, 'schedule')->widget(

        'trntv\yii\datetime\DateTimeWidget',
        [
            'phpDatetimeFormat' => 'yyyy-MM-dd\'T\'HH:mm:ssZZZZZ',
            'clientOptions' => [
                //'inline' => true,
                'minDate' => new \yii\web\JsExpression('new Date("' . $date->format('Y-m-d') . '")'),
                'allowInputToggle' => true,
                'sideBySide' => true,
                'locale' => 'it-IT',
                'disabledDates' => $date_disabled,
                'widgetPositioning' => [
                    'horizontal' => 'auto',
                    'vertical' => 'auto'
                ],
                //'format' => 'dddd d MMMM YYYY : HH:mm',
                'stepping' => '30',
            ]
        ])`
    
    opened by trinkity 3
  • Failed to parse time string (16/08/2016 00:00) at position 0 (1)

    Failed to parse time string (16/08/2016 00:00) at position 0 (1)

    Hi,

    Thanks for creating this widget. I installed it successfully but I cannot set 'MM/dd/yyyy HH:mm' format for phpDatetimeFormat, it allows me to set following format:

    'phpDatetimeFormat' => 'dd/MM/yyyy HH:mm',

    Hence I cannot submit dates which are more than 12 because I get following error:

    '16/08/2016 00:00' is not a valid date time value: DateTime::__construct(): Failed to parse time string (16/08/2016 00:00) at position 0 (1): Unexpected character

    Could you please help me.

    opened by tigran-k 1
Releases(1.1.1)
Owner
Yevhen Terentiev
Passionate software engineer
Yevhen Terentiev
An enhanced FileInput widget for Bootstrap 4.x/3.x with file preview, multiple selection, and more features (sub repo split from yii2-widgets)

yii2-widget-fileinput The FileInput widget is a customized file input widget based on Krajee's Bootstrap FileInput JQuery Plugin. The widget enhances

Kartik Visweswaran 227 Nov 6, 2022
Yii2 SwitchInput widget turns checkboxes and radio buttons into toggle switchinputes

Yii2 SwitchInput widget turns checkboxes and radio buttons into toggle switchinputes

Kartik Visweswaran 38 Sep 21, 2022
An enhanced Yii 2 widget encapsulating the HTML 5 range input (sub repo split from yii2-widgets)

yii2-widget-rangeinput The RangeInput widget is a customized range slider control widget based on HTML5 range input. The widget enhances the default H

Kartik Visweswaran 19 Mar 12, 2022
Simple RBAC Manager for Yii2 (minify of yii2-admin)

Yii2 Mimin Simple RBAC Manager fo Yii 2.0. Minify of yii2-admin extension with awesome features Attention Before you install and use this extension, t

Hafid Mukhlasin 52 Sep 22, 2022
yii2-app-advanced with Twitter Bootstrap 5

Yii 2 Advanced Project Template is a skeleton Yii 2 application best for developing complex Web applications with multiple tiers.

Nedarta 1 Nov 5, 2021
Yii2 extension for format inputs based on AutoNumeric.js

Yii2 extension for format inputs based on AutoNumeric.js

extead 2 Oct 7, 2019
Tarantool connector for yii2 framework. Allow to use activerecord, schemas, widgets and more.

Tarantool connector for yii2 framework Tarantool connector for yii2 framework. Allow to use framework abstractions such as ActiveRecord, Schema, Table

Andrey 11 Nov 21, 2021
Yii 2 widget for the Froala WYSIWYG HTML Editor.

Yii Framework Froala WYSIWYG HTML Editor Yii 2 widget for Froala Wysiwyg editor. Installation The preferred way to install this extension is through c

Froala 99 Sep 21, 2022
Extends Yii Menu widget

Extends Yii Menu widget. This widget offers a scrollspy and affixed enhanced navigation (upto 2-levels) to highlight sections and secondary sections in each page.

Kartik Visweswaran 15 Mar 12, 2022
DepDrop widget is a Yii 2 wrapper for the dependent-dropdown jQuery plugin by Krajee.

yii2-widget-depdrop The DepDrop widget is a Yii 2 wrapper for the dependent-dropdown jQuery plugin by Krajee. This plugin allows multi level dependent

Kartik Visweswaran 82 Nov 27, 2022
Web Push Notifications brought to Yii2

Web Push Notifications for Yii 2 An extension for implementing Web Push Notifications on your website in a breeze. Documentation is at docs/README.md

Mehdi Achour 12 May 19, 2022
Prometheus exporter for Yii2

yii2-prometheus Prometheus Extension for Yii 2 This extension provides a Prometheus exporter component for Yii framework 2.0 applications. This extens

Mehdi Achour 3 Oct 27, 2021
Yii2-symfonymailer - Yii 2 Symfony mailer extension.

Yii Mailer Library - Symfony Mailer Extension This extension provides a Symfony Mailer mail solution for Yii framework 2.0. For license information ch

Yii Software 28 Dec 22, 2022
Yii2 console application used to write our processors of methods to responsible to client calling.

Microservice Application Skeleton Yii2 console application used to write our processors of methods to responsible to client calling. This application

Jafaripur 0 Mar 10, 2022
A Yii2 module for embedding social plugins and widgets.

yii2-social Module that enables access to social plugins for Yii Framework 2.0. It includes support for embedding plugins from the following networks

Kartik Visweswaran 92 May 29, 2022
Pug Yii2 adapter

Yii 2 Pug (ex Jade) extension This extension provides a view renderer for Pug templates for Yii framework 2.0 applications. Support GutHub issues Inst

Pug PHP 8 Jun 17, 2022
This is Yii2 utilities

YII2-UTILITY This is Yii2 utilities. Requirements PHP >= 7.4 Curl extension for PHP7 must be enabled. Download Using Composer From your project direct

null 0 Jun 30, 2022
Alejandro Flores, Php Yii2 Emoac

Prueba Tecnica Emoac Proyecto basado en PHP con Yii2. Hecho por Alejandro Flores, Ingeniero en informática. Este proyecto consta de un CRUD de product

FlamesAlejandro 2 Sep 13, 2022
A collapsible side navigation menu built to seamlessly work with Bootstrap framework

yii2-widget-sidenav This widget is a collapsible side navigation menu built to seamlessly work with Bootstrap framework. It is built over Bootstrap st

Kartik Visweswaran 36 Apr 9, 2022