fix(forms): consistent treatment of empty #63456
Closed
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.
Removes custom handling of emptiness in several of the validators and replaces it with a common
isEmpty
check. The common empty check considered the following values to be empty:null
,undefined
,''
,false
,NaN
Generally most validators should treat an empty value as valid. This aligns with both the behavior or native HTML validators and reactive forms validators.
As an example, consider an optional email field. If the email validator considered empty string to be an invalid email, there would be no way for the user to not enter it.
There are several exceptions to this rule:
required
whose entire purpose is to ensure that the field is not emptyvalidateStandardSchema
which should subject all values including empty ones to the specified standard schema. It is up to the schema to decide whether an empty value is valid or notvalidate
/validateAsync
which leaves it up to the user's custom validation logic to decide if an empty value is valid.