metisfw/form-datetime
Composer 安装命令:
composer require metisfw/form-datetime
包简介
Forms control for adding date, date&time and time fields for Nette Framework
README 文档
README
Based on abandoned library https://github.com/ipublikuj-archive/form-datetime by Adam Kadlec.
Forms control for adding date, date&time and time fields for Nette Framework forms
This extension is based on two datetime libraries. For Bootstrap template is used js library from Sebastien Malot and for UIkit template is used their datepicker and timepicker extensions.
Installation
The best way to install metisfw/form-datetime is using Composer:
{
"require": {
"metisfw/form-datetime": "dev-master"
}
}
or
$ composer require metisfw/form-datetime:@dev
After that you have to register extension in config.neon.
extensions: formDateTime: MetisFW\FormDateTime\DI\FormDateTimeExtension
In Nette 2.0, registration is done in
app/bootstrap.php:
$configurator->onCompile[] = function ($configurator, $compiler) { $compiler->addExtension('formDateTime', new MetisFW\FormDateTime\DI\FormDateTimeExtension); };
And you also need to include static files into your page:
<script src="{$basePath}/libs/metisfw.formDateTime.js"></script> </body>
note: You have to upload static files from client-site folder to your project.
Usage
$form->addDatePicker('date', 'Date picker:'); $form->addDateTimePicker('datetime', 'Date & time picker:'); $form->addTimePicker('time', 'Time picker:');
You can pass configuration for each type of form field:
Settings for all types
You can enable additional buttons which can control showed form field:
$form ->addDateTimePicker('datetime', 'Date & time picker:') // Enable trigger button to open date/time picker ->enableTriggerButton() // Enable cancel button to clear field ->enableCancelButton();
Settings for Date picker
Just setup how date picker window should display:
$form ->addDatePicker('date', 'Date picker:') // Set week start day ->setWeekStart(1) // 0 for sunday, 6 for saturday // Disable some days from week, this days can not be selected via picker ->setDaysOfWeekDisabled([0, 6]);
Settings for Time picker
Just setup how time picker window should display:
$form ->addTimePicker('time', 'Time picker:') // Set week start day ->setShowMeridian(TRUE) // Show time in meridian format (e.g. 04:15 PM)
Settings for Date & Time picker
This type of picker combines all settings from previous two types.
Defining date and time formats
You can set for each field its format how value should be displayed in form.
$form ->addDateTimePicker('datetime', 'Date & time picker:') // Set date format ->setDateFormat('yyyy/dd/mm') // Set time format ->setTimeFormat('hh:ii:ss');
This two methods require JS format, so for two digits day/mont and four digits year write dd/mm/yyyy etc.
Validation
Validation can be done as on usual text input and also this fields support special ranges values.
If you need to define some range for selecting value, you can use filed range rule:
$form ->addDateTimePicker('datetime', 'Date & time picker:') // Set date format ->addRule(\MetisFW\FormDateTime\Controls\DateTime::DATE_TIME_RANGE, 'Date must be between defined values', [(new Utils\DateTime(2015-01-01)), (new Utils\DateTime(2015-09-01))]);
This rule will also create min and max for picker window, so user will be not able to pick date out of defined range.
There are also nex two rules for minimal and maximal value:
$form ->addDateTimePicker('datetime', 'Date & time picker:') // Set date format ->addRule(\MetisFW\FormDateTime\Controls\DateTime::DATE_TIME_MIN, 'Date must be higher than selected', (new Utils\DateTime(2015-01-01))); ->addRule(\MetisFW\FormDateTime\Controls\DateTime::DATE_TIME_MAX, 'Date must be lower than selected', (new Utils\DateTime(2015-09-01)));
Custom templates and rendering
This control come with templating feature, that mean form element of this control is rendered in latte template. There are 3 predefined templates:
- bootstrap.latte if you are using Twitter Bootstrap
- uikit.latte if you are using YooTheme UIKit
- default.latte for custom styling (this template is loaded as default)
But be aware, if you choose different template than UIkit or Bootstrap, JS will be deactivated!
You can also define you own template if you need to fit this control into your layout.
Template can be set in form definition:
$form ->addDateTimePicker('datetime', 'Date & time picker:') ->setTemplateFile('path/to/your/template.latte');
or in manual renderer of the form:
{?$form['datetime']->setTemplateFile('path/to/your/template.latte')}
{input datetime class => "some-custom-class"}
and if you want to switch default template to bootstrap or uikit just it write into template setter:
$form ->addDateTimePicker('datetime', 'Date & time picker:') ->setTemplateFile('bootstrap.latte');
or
{?$form['datetime']->setTemplateFile('bootstrap.latte')}
{input datetime class => "some-custom-class"}
metisfw/form-datetime 适用场景与选型建议
metisfw/form-datetime 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 399 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 12 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「form」 「time」 「date」 「tools」 「nette」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 metisfw/form-datetime 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 metisfw/form-datetime 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 metisfw/form-datetime 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Tools to convert between .NET and PHP date formats
Adds the EDTF data type to Wikibase
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
Date component is a set of methods to help with the manipulation of dates.
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
统计信息
- 总下载量: 399
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2021-12-30