Skip to content

Conversation

mmalerba
Copy link
Contributor

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 empty
  • validateStandardSchema 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 not
  • validate/validateAsync which leaves it up to the user's custom validation logic to decide if an empty value is valid.

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*
  empty
- `validateStandardSchema` 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 not
- `validate`/`validateAsync` which leaves it up to the user's custom
  validation logic to decide if an empty value is valid.
@mmalerba mmalerba requested review from leonsenft and alxhub August 28, 2025 22:33
@mmalerba mmalerba added the target: major This PR is targeted for the next major release label Aug 28, 2025
@pullapprove pullapprove bot requested review from crisbeto and kirjs August 28, 2025 22:33
@ngbot ngbot bot added this to the Backlog milestone Aug 28, 2025
Co-authored-by: Leon Senft <leonsenft@users.noreply.github.com>
@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Aug 28, 2025
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed-for: public-api

Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: public-api

@mmalerba
Copy link
Contributor Author

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

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: forms target: major This PR is targeted for the next major release
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants