Skip to content

Parse typed dates with the display format when an alt input is used - #160

Open
Tklaversma wants to merge 1 commit into
coolsam726:mainfrom
Tklaversma:fix/manual-input-alt-format
Open

Tklaversma wants to merge 1 commit into
coolsam726:mainfrom
Tklaversma:fix/manual-input-alt-format

Conversation

@Tklaversma

@Tklaversma Tklaversma commented Sep 26, 2026 •

Copy link
Copy Markdown

Summary

When a field has a displayFormat() that differs from its format(), 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')

  • Typing 23-12-2026 (or 23.12.2026) and leaving the field gives 01-01-2026.
  • Picking 15 December 2026 in the calendar also gives 01-01-2026.

The cause is in commitManualInput(). It reads the text of the visible alt input, which is written in altFormat, but parses it with dateFormat:

const inputValue = this.fp.altInput?.value ?? this.fp.input.value
// ...
const parsed = this.fp.parseDate(inputValue, this.fp.config.dateFormat)

With dateFormat Y-m-d, the text 23-12-2026 only matches the Y token, so flatpickr keeps its default of 1 January for the day and the month. The method runs on blur and in onClose, 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 using dateFormat as before.

resources/dist/components/flatpickr.js is rebuilt with node bin/build.js. Rebuilding the unchanged main first 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') and displayFormat('d-m-Y'):

  • Before the change, typing 23.12.2026 gives 01-01-2026, and a calendar click on 15 September 2026 gives 01-01-2026.
  • After the change, typing 23.12.2026 gives 23-12-2026 with state 2026-12-23.
  • Typing 24-12-2026 gives state 2026-12-24.
  • A calendar click on 15 September 2026 gives state 2026-09-15.
  • The Livewire state matches in all three cases, in a repeater on a page and in an action modal.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant