coolsam/flatpickr 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

coolsam/flatpickr

Composer 安装命令:

composer require coolsam/flatpickr

包简介

Flatpickr input for Filamentphp

README 文档

README

CI Coverage Latest Version on Packagist Total Downloads

A Filament form field powered by Flatpickr — date, time, range, week, month, year, and multi-date picking with a fluent API.

Filament Flatpickr preview

Supported versions

Package Filament Laravel PHP
v5.x (current) 4.x, 5.x 11.x – 13.x 8.2 – 8.5 (PHP 8.5 from Laravel 12+; Laravel 13 from PHP 8.3+)
v4.x 3.x 10.x – 11.x 8.1 – 8.3
v2.x 2.x 9.x – 10.x 8.0 – 8.2

Installation

Install the package with Composer:

composer require coolsam/flatpickr

Publish assets and configuration:

php artisan flatpickr:install

This publishes config/flatpickr.php and assets to public/vendor/flatpickr. You will be prompted to overwrite existing files when upgrading.

After upgrading, refresh Filament assets:

php artisan filament:upgrade

Quick start

use Coolsam\Flatpickr\Forms\Components\Flatpickr;

Flatpickr::make('published_at')
    ->format('Y-m-d')
    ->minDate(today()->startOfYear())
    ->maxDate(today());

Picker modes

One component covers every Flatpickr mode you need:

Mode Helper Typical format
Date Flatpickr::make('date') Y-m-d
Date & time ->time(true) or ->timePicker() Y-m-d H:i / H:i
Range ->rangePicker() array of date strings, or two fields with ->rangeEnd()
Multiple dates ->multiplePicker() array of date strings
Week ->weekPicker() W Y
Month ->monthPicker() Y-m
Year ->yearPicker() Y

Short examples

use Coolsam\Flatpickr\Forms\Components\Flatpickr;

Flatpickr::make('start_time')->timePicker();
Flatpickr::make('week_number')->weekPicker()->format('W Y');
Flatpickr::make('month')->monthPicker()->format('Y-m')->displayFormat('F Y');
Flatpickr::make('year')->yearPicker();
Flatpickr::make('range')->rangePicker();
Flatpickr::make('starts_at')->rangePicker()->rangeEnd('ends_at')->format('Y-m-d');
Flatpickr::make('occupied_slots')->multiplePicker()->format('Y-m-d')->displayFormat('F j, Y');

Configuration

Most fluent methods mirror Flatpickr's options. The API is inspired by Filament's date/time fields and works as a drop-in alternative with Flatpickr-specific behaviour.

use Coolsam\Flatpickr\Enums\FlatpickrMode;
use Coolsam\Flatpickr\Enums\FlatpickrMonthSelectorType;
use Coolsam\Flatpickr\Enums\FlatpickrPosition;
use Coolsam\Flatpickr\Forms\Components\Flatpickr;

Flatpickr::make('event_date')
    ->format('Y-m-d')
    ->displayFormat('F j, Y')
    ->allowInput()
    ->altInput()
    ->minDate(fn () => today()->startOfYear())
    ->maxDate(fn () => today())
    ->disableDates(['2024-07-25', '2024-07-26'])
    ->rangeSeparator(' to ')
    ->conjunction(',')
    ->hourIncrement(1)
    ->minuteIncrement(10)
    ->seconds(false)
    ->weekNumbers()
    ->time24hr()
    ->inline()
    ->disableMobile()
    ->mode(FlatpickrMode::RANGE) // or ->rangePicker(), ->multiplePicker()
    ->monthSelectorType(FlatpickrMonthSelectorType::DROPDOWN)
    ->position(FlatpickrPosition::AUTO_CENTER)
    ->showMonths(2)
    ->timePicker()
    ->weekPicker()
    ->monthPicker()
    ->yearPicker()
    ->rangePicker()
    ->multiplePicker();

See the Flatpickr documentation for details on each option.

State types

Picker Dehydrated state
Date, time, week, month, year string or CarbonInterface
Range, multiple array of date strings or CarbonInterface instances
Range with ->rangeEnd('ends_at') Two separate fields: start and end strings or CarbonInterface instances

Split range across two fields

When your model uses separate starts_at and ends_at columns, bind the range picker to the start field and name the end field explicitly. One picker is shown; both attributes are hydrated, synced live, and dehydrated on save.

Flatpickr::make('starts_at')
    ->label('Event dates')
    ->rangePicker()
    ->rangeEnd('ends_at')
    ->format('Y-m-d');

Do not add a second Flatpickr on ends_at. Validation rules on ends_at (for example after:starts_at) still work because the end value is kept in sync while the user selects a range.

Date & time range

Use ->time(true) with a format that includes hours and minutes. displayFormat() controls what the user sees in the input (Flatpickr tokens, not PHP date() tokens). Storage and dehydration still use format().

Flatpickr::make('starts_at')
    ->label('Event schedule')
    ->rangePicker()
    ->rangeEnd('ends_at')
    ->time(true)
    ->format('Y-m-d H:i')              // saved to starts_at / ends_at
    ->displayFormat('M j, Y h:i K')    // e.g. Jun 14, 2024 7:00 AM to Jun 17, 2024 5:00 PM
    ->rangeSeparator(' to ');

Ensure your model casts both columns as datetime. The picker UI lets you choose a date and time for each end of the range in one calendar.

See RFC 0001 for the full design.

Themes

Set the global theme in config/flatpickr.php using a FlatpickrTheme enum value:

use Coolsam\Flatpickr\Enums\FlatpickrTheme;

return [
    'theme' => FlatpickrTheme::DEFAULT, // recommended
];

Recommendation: Use the DEFAULT theme. It is styled with Tailwind to match Filament, including dark mode. Bundled Flatpickr themes may not align with your panel styling.

Theme previews are included in the screenshots below.

Screenshots

Picker modes

Single date

Single date picker

Multiple dates

Multiple date picker

Date range

Date range picker

Date & time

Date-time picker

Time only

Time-only picker

Multiple months

Show multiple months

Week

Week picker

Month

Month picker

Theme gallery

Default (recommended)

Default theme

Airbnb

Airbnb theme

Light

Light theme

Dark

Dark theme

Confetti

Confetti theme

Material Blue

Material Blue theme

Material Green

Material Green theme

Material Orange

Material Orange theme

Material Red

Material Red theme

Testing

composer test

Changelog

See CHANGELOG for release notes.

Contributing

See CONTRIBUTING for guidelines.

Security

Report vulnerabilities according to our security policy.

Credits

License

The MIT License. See LICENSE.md.

coolsam/flatpickr 适用场景与选型建议

coolsam/flatpickr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 249.09k 次下载、GitHub Stars 达 99, 最近一次更新时间为 2023 年 08 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「flatpickr」 「coolsam」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 coolsam/flatpickr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 coolsam/flatpickr 我们能提供哪些服务?
定制开发 / 二次开发

基于 coolsam/flatpickr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 249.09k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 99
  • 点击次数: 25
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 99
  • Watchers: 3
  • Forks: 55
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-02