Skip to content

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

Open
shteynu wants to merge 1 commit into
angular:mainfrom
shteynu:fix/datepicker-parse-error-signal-forms
Open

shteynu wants to merge 1 commit into
angular:mainfrom
shteynu:fix/datepicker-parse-error-signal-forms

Conversation

@shteynu

@shteynu shteynu commented Oct 12, 2026

Copy link
Copy Markdown

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(COMPONENT): MatDatePicker

1 participant