Repository navigation
Conversation
…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
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.
Fixes #33740.
When a datepicker input is bound to a signal form with
[formField], thematDatepickerParseerror goes stale whenever the model value staysnull:foo) into an empty input does not add the error;Cause
Signal forms compute the errors of a CVA's legacy validators in a
computedthat re-runs when the control value changes or when the validator calls itsregisterOnValidatorChangecallback. InMatDatepickerInputBase._onInput(), thenulltonullpath 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, becausesetValuealways re-runs the validators.Fix
Call
_validatorOnChange()whenever the parse state flips while the value stays the same, includingnulltonull. The branch that already did this for an unchanged non-null date behaves as before.With reactive forms, the
nulltonullcase with a changed parse state now also triggersupdateValueAndValidity()after thesetValue(null)call. It gives the same result, with one extravalueChanges/statusChangesemission in that case.Testing
Two tests in
datepicker.spec.tsuse a real signal form (form()+FormField). Both fail onmainand pass with this change:foointo an empty input setsmatDatepickerParse;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_chromiumpass locally.