Repository navigation
Parse typed dates with the display format when an alt input is used - #160
Tklaversma wants to merge 1 commit into
Conversation
commitManualInput() reads the text of the visible alt input, which is
formatted with altFormat (the displayFormat() of the field), but parsed
it with dateFormat (the storage format). With displayFormat('d-m-Y') and
format('Y-m-d'), the text "23-12-2026" only matches the year token, so
the date became 2026-01-01.
This runs on blur and when the calendar closes, so it also overwrote
dates picked from the calendar. Flatpickr's own blur handler already
uses altFormat for the alt input; this makes commitManualInput() do the
same.
Claude-Session: https://claude.ai/code/session_013QYJHdp6LqgM1Tif1xBUAZ
|
We hit this in production as well, right after upgrading from 5.1.0 to 5.3.0 (Filament 5.10.3, Livewire 4.4.8). Our setup is We traced it to the same line in As a workaround we pinned the package to 5.1.1, which doesn't have |
Summary
When a field has a
displayFormat()that differs from itsformat(), every date a user enters is saved as 1 January of the entered year.Example:
Flatpickr::make('date')->allowInput()->format('Y-m-d')->displayFormat('d-m-Y')23-12-2026(or23.12.2026) and leaving the field gives01-01-2026.01-01-2026.The cause is in
commitManualInput(). It reads the text of the visible alt input, which is written inaltFormat, but parses it withdateFormat:With
dateFormatY-m-d, the text23-12-2026only matches theYtoken, so flatpickr keeps its default of 1 January for the day and the month. The method runs on blur and inonClose, so it also overwrites a date that was just picked from the calendar: flatpickr has already set the correct date, and this method then replaces it.This PR parses the alt input text with
altFormat, the same way flatpickr's own blur handler does (e.target === self.altInput ? self.config.altFormat : self.config.dateFormat). When there is no alt input, it keeps usingdateFormatas before.resources/dist/components/flatpickr.jsis rebuilt withnode bin/build.js. Rebuilding the unchangedmainfirst gave a byte-identical file, so the dist diff contains only this change.Linked issues
None. I found this in a Filament 5 app after upgrading to v5.3.0 and did not open a separate issue.
Test plan
The repository has no JavaScript test runner, only Pest tests for the PHP side, so I tested this change by hand in a Filament 5.8 app, with
allowInput(),format('Y-m-d')anddisplayFormat('d-m-Y'):23.12.2026gives01-01-2026, and a calendar click on 15 September 2026 gives01-01-2026.23.12.2026gives23-12-2026with state2026-12-23.24-12-2026gives state2026-12-24.2026-09-15.