Skip to content

Add signal form config option to process async validation even when sync errors are present #70815

Description

@neodescis

Which @angular/* package(s) are relevant/related to the feature request?

forms

Description

My use case involves validateStandardSchema. We have Zod schemas defined for our forms, and we are validating the forms with them using validateStandardSchema. We also have some of Angular's required() validators thrown in as well. The trouble is, we have a reused sub-schema that we need to add async validation to. This async Zod validation at some of the form leaf nodes (via async .superRefine() calls) causes the entire schema to return a promise instead of a synchronous value, and as such, Angular ignores the promise value whenever the form has other sync errors from the required() validators. To make matters worse, the Zod async validation is still run, but Angular is dropping the results on the floor.

So, my proposal is this: would it be possible/acceptable to add a configuration option to either the form itself, or to validateStandardSchema, to not ignore these async errors? I understand the reasoning to avoid expensive async validators when possible, but in this scenario, they aren't even being avoided, just ignored.

Proposed solution

Add a configuration option to FormOptions, called something like "processAsyncValidators", with possible values of "whenSyncValid" (default), and "always", which is consumed in validateAsync().

Alternatives considered

  1. Create separate sync and async schemas: rejected because the composable schema structure would have to be duplicated unnecessarily
  2. Create more granular, field-level schemas: rejected because this violates the concept of having a single standard schema for a form, and shifts complexity from the schema to the Angular component

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions