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.
- jQuery and jQueryUI
- Timepicker addon version 1.1.0 or newer
$ 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):
<scripttype='text/javascript' src="{$basePath}/scripts/jquery-ui-timepicker-addon.js"></script><scripttype='text/javascript' src="{$basePath}/scripts/dateInput.js"></script><linkrel="stylesheet" type="text/css" href="{$basePath}/styles/jquery-ui-timepicker-addon.css"><linkrel="stylesheet" type="text/css" href="{$basePath}/styles/dateInput.css">register the addon in your bootstrap.php:
Vodacek\Forms\Controls\DateInput::register();
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-localchangeYear: true}},date: {dateFormat: 'd.m.yy'},month: {dateFormat: 'MM yy'},week: {dateFormat: "w. 'week of' yy"},time: {timeFormat: 'H:mm'},options: {// global optionscloseText: "Close"}});});$form->addDate('datetimeLocal', 'Local datetime', DateInput::TYPE_DATETIME_LOCAL)
->setRequired()
->setDefaultValue(newDateTimeImmutable())
->addRule(Form::RANGE, null, array(newDateTimeImmutable('-2 years'), newDateTimeImmutable('+2 years')));