Skip to content

fix(material/datepicker): update parse error with signal forms when value stays null - #33951

Merged
crisbeto merged 1 commit into
angular:mainfrom
shteynu:fix/datepicker-parse-error-signal-forms
Oct 16, 2026
Merged

crisbeto merged 1 commit into
angular:mainfrom
shteynu:fix/datepicker-parse-error-signal-forms

Conversation

@shteynu

@shteynu shteynu commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #33740.

When a datepicker input is bound to a signal form with [formField], the matDatepickerParse error goes stale whenever the model value stays null:

  • typing an unparseable value (e.g. foo) into an empty input does not add the error;
  • erasing an unparseable value does not clear it, so the form stays invalid on an empty field (the case in the issue).

Cause

Signal forms compute the errors of a CVA's legacy validators in a computed that re-runs when the control value changes or when the validator calls its registerOnValidatorChange callback. In MatDatepickerInputBase._onInput(), the null to null path calls _cvaOnChange(null), which signal forms ignore because the value did not change, and it never calls _validatorOnChange(): that call was only in the branch for a non-null, unchanged date. Reactive forms don't hit this, because setValue always re-runs the validators.

Fix

Call _validatorOnChange() whenever the parse state flips while the value stays the same, including null to null. The branch that already did this for an unchanged non-null date behaves as before.

With reactive forms, the null to null case with a changed parse state now also triggers updateValueAndValidity() after the setValue(null) call. It gives the same result, with one extra valueChanges/statusChanges emission in that case.

Testing

Two tests in datepicker.spec.ts use a real signal form (form() + FormField). Both fail on main and pass with this change:

  • typing foo into an empty input sets matDatepickerParse;
  • setting a date, typing foo, then clearing the input removes it.

//src/material/datepicker:unit_tests_chromium (407 tests, including the date range input) and //src/material/input:unit_tests_chromium pass locally.

…alue stays null

When the user types an unparseable value into an empty datepicker input, or erases an
unparseable value, the model value stays `null`. Reactive forms re-run the validators on
every `setValue`, but signal forms skip writes that don't change the value, so the
`matDatepickerParse` error was neither added nor cleared in those cases.

Notify the forms module that the validators changed whenever the parse state flips while
the value stays the same, including the `null` to `null` case.

Fixes angular#33740.
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Oct 16, 2026
@crisbeto
crisbeto merged commit 3f9f22b into angular:main Oct 16, 2026
29 of 31 checks passed
@crisbeto

Copy link
Copy Markdown
Member

This PR was merged into the repository. The changes were merged into the following branches:

crisbeto pushed a commit that referenced this pull request Oct 16, 2026
…alue stays null (#33951)

When the user types an unparseable value into an empty datepicker input, or erases an
unparseable value, the model value stays `null`. Reactive forms re-run the validators on
every `setValue`, but signal forms skip writes that don't change the value, so the
`matDatepickerParse` error was neither added nor cleared in those cases.

Notify the forms module that the validators changed whenever the parse state flips while
the value stays the same, including the `null` to `null` case.

Fixes #33740.

(cherry picked from commit 3f9f22b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: material/datepicker target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(COMPONENT): MatDatePicker

2 participants