2017 © Pedro Peláez
 

library nette-datetimefields

Form component for date, time and datetime inputs with automatic conversion to DateTime.

image

livioribeiro/nette-datetimefields

Form component for date, time and datetime inputs with automatic conversion to DateTime.

  • Monday, April 7, 2014
  • by livioribeiro
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6,014 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

NetteDateTimeFields

Form component for date, time and datetime inputs with automatic conversion to DateTime., (*1)

Setup

Add the DateTimeFormExtension to your config.neon, (*2)

extensions:
  - NetteDateTimeFields\DateTimeFormExtension

or call register method in bootstrap.php, (*3)

use NetteDateTimeFields\DateTimeFormExtension
DateTimeFormExtension::register();

Usage

Simply call addDate(), addTime() or addDateTime() on the Form object:, (*4)

$form = new Nette\Application\UI\Form();
$form->addDate('date', 'date', $format = 'd/m/Y');
$form->addTime('time', 'time', $format = 'H:i');
$form->addDateTime('dateTime', 'dateTime', $dateFormat = 'd/m/Y', $timeFormat = 'H:i', $separator = ' ')

You can also add a range validation:, (*5)

use NetteDateTimeFields\Controls\DateTimeBase;

$form = new Nette\Application\UI\Form();
$form->addDate('date', 'date', 'Y-m-d')
    ->addRule(DateTimeBase::DATETIME_RANGE, 'message',
        ['1970-01-01', '2070-01-01']); // \DateTime or string 
$form->addTime('time', 'time')
    ->addRule(DateTimeBase::DATETIME_RANGE, 'message',
        ['08:00', '16:30']);
$form->addDateTime('dateTime', 'dateTime')
    ->addRule(DateTimeBase::DATETIME_RANGE, 'message',
        ['01/01/1970', '01/01/2070']);

The parameters can be either a \DateTime object or a string formatted accondingly to the format specified., (*6)

DateTime range validation can receive 4 parameters, which the third and fourth validates the time range of the given date. The following will not validate, for example, a date and time like '01/01/2010 07:00'., (*7)

$form->addDateTime('dateTime', 'dateTime')
    ->addRule(DateTimeBase::DATETIME_RANGE, 'message',
        ['01/01/1970', '01/01/2070', '08:00', '16:30']);

The Versions

07/04 2014

dev-master

9999999-dev https://github.com/livioribeiro/NetteDateTimeFields

Form component for date, time and datetime inputs with automatic conversion to DateTime.

  Sources   Download

BSD-3-Clause

The Requires

 

date time input nette datetime form input