Giter Site home page Giter Site logo

dodo-it / nettedatetimefields Goto Github PK

View Code? Open in Web Editor NEW

This project forked from livioribeiro/nettedatetimefields

0.0 1.0 0.0 11 KB

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

License: BSD 3-Clause "New" or "Revised" License

PHP 100.00%

nettedatetimefields's Introduction

NetteDateTimeFields

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

Setup

Add the DateTimeFormExtension to your config.neon

extensions:
  - NetteDateTimeFields\DateTimeFormExtension

or call register method in bootstrap.php

use NetteDateTimeFields\DateTimeFormExtension
DateTimeFormExtension::register();

Usage

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

$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:

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.

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'.

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

nettedatetimefields's People

Contributors

livioribeiro avatar dakorpar avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.