Repository navigation
Parse typed dates with the display format when an alt input is used - #160
Open
Tklaversma wants to merge 1 commit into
Open
Tklaversma wants to merge 1 commit into
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
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.