Skip to content

Form component for Nette Framework supporting all HTML 5 date inputs.

License

Notifications You must be signed in to change notification settings

Fire-man-x/DateInput

 
 

Repository files navigation

DateInput

Nette forms component for selecting date and time values.

In PHP this addon works with DateTime objects, in the browser it uses jqueryUI calendar with timepicker addon. Look at some examples at the demo page.

Build Status Latest Stable Version Total Downloads License

JS dependencies (recomended)

Installation

$ composer require voda/date-input

package can be also installed using bower: $ bower install voda-date-input --save

insert required javascript and style files into your layout (order of scripts is important):

<script type='text/javascript' src="{$basePath}/scripts/jquery-ui-timepicker-addon.js"></script>
<script type='text/javascript' src="{$basePath}/scripts/dateInput.js"></script>
<link rel="stylesheet" type="text/css" href="{$basePath}/styles/jquery-ui-timepicker-addon.css">
<link rel="stylesheet" type="text/css" href="{$basePath}/styles/dateInput.css">

Registering

Register the addon in your bootstrap.php

Vodacek\Forms\Controls\DateInput::register();

Or use DI extension

config.neon:

extensions:
    dateInput: Vodacek\Forms\Controls\Extension

If you want use jQuery calendar (not necessary)

initialize the calendar using javascript:

$(document).ready(function() {
    $('input[data-dateinput-type]').dateinput({
        'datetime-local': {
            dateFormat: 'd.m.yy',
            timeFormat: 'H:mm',
            options: { // options for type=datetime-local
                changeYear: true
            }
        },
        date: {
            dateFormat: 'd.m.yy'
        },
        month: {
            dateFormat: 'MM yy'
        },
        week: {
            dateFormat: "w. 'week of' yy"
        },
        time: {
            timeFormat: 'H:mm'
        },
        options: { // global options
            closeText: "Close"
        }
    });
});

Usage

$form->addDate('datetimeLocal', 'Local datetime', DateInput::TYPE_DATETIME_LOCAL)
        ->setRequired()
        ->setDefaultValue(new DateTimeImmutable())
        ->addRule(Form::RANGE, null, array(new DateTimeImmutable('-2 years'), new DateTimeImmutable('+2 years')));

$form->addDate('date', 'Date', DateInput::TYPE_DATE);

$form->addDate('time', 'Time', DateInput::TYPE_TIME);

About

Form component for Nette Framework supporting all HTML 5 date inputs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 52.2%
  • JavaScript 42.3%
  • CSS 4.4%
  • Other 1.1%