Skip to content

ROU-12898 fix DatePicker onChange not firing on manual -1 day entry#27

Draft
gnbm wants to merge 1 commit into
masterfrom
ROU-12898
Draft

ROU-12898 fix DatePicker onChange not firing on manual -1 day entry#27
gnbm wants to merge 1 commit into
masterfrom
ROU-12898

Conversation

@gnbm

@gnbm gnbm commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes the DatePicker (flatpickr) failing to fire onChange when a user manually types a date one day earlier than the currently selected date, under negative timezone offsets

Root cause

onBlur gates whether to call setDate(..., true, ...) (which fires onChange) on a valueChanged check:

self.formatDate(new Date(hiddenInputValue), self.config.altFormat)

With TimeFormat.Disabled the hidden value is a date-only string (e.g. "2026-06-25"). Per ECMAScript, a date-only string passed to new Date() is parsed as UTC midnight. Under a negative UTC offset (e.g. UTC−02:00) that instant renders as the previous day in local time, so formatDate(...) returns "2026-06-24".

Consequently, after selecting today and typing the previous day, the typed value equals the (shifted) baseline → valueChanged = falsesetDate/onChange are skipped. Typing −2 days differs from the shifted baseline, so it still fires — matching the ticket's exact signature ("−1 fails, −2 works, negative offsets only").

Fix

Parse the hidden value with flatpickr's own self.parseDate(hiddenInputValue, self.config.dateFormat), which builds the date from local components (no UTC shift), consistent with the rest of flatpickr. An unparseable/empty value is treated as changed so onChange is not wrongly suppressed.

Testing

  • npm run test:typecheck — passes.
  • npm run test:unit4 failed / 107 passed, identical to master baseline (the same 4 pre-existing failures: API destroy(), onKeyDown ... Enter, time-picker focuses out, onBlur doesn't misfire). This change adds no new failures.
  • npm run build — succeeds; fix present in dist/flatpickr.js and dist/esm/index.js.

The onBlur change-detection compared the typed value against
new Date(hiddenInputValue). For a date-only value ("Y-m-d") the
Date constructor parses it as UTC midnight, which renders as the
previous day under negative timezone offsets. A manual entry of the
previous day therefore looked unchanged, so setDate/onChange were
suppressed (a -2 day entry still differed and fired).

Parse the hidden value with flatpickr's own parseDate (local time)
using config.dateFormat instead, and treat an unparseable value as
changed.
@gnbm gnbm added the bug Something isn't working label Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant