Skip to content

fix(forms): allow multiple async validators#69625

Open
JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:forms/validators-async-resource
Open

fix(forms): allow multiple async validators#69625
JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:forms/validators-async-resource

Conversation

@JeanMeche

Copy link
Copy Markdown
Member

When a parent form element defines an async validator, its resource's params function needs to evaluate syncValid(), which causes unvisited child form nodes to be lazily instantiated. If any of these lazily instantiated child nodes also define an async validator, their resource is initialized while the parent's params function is still evaluating. This incorrectly triggers Angular core's NG0992 guard (Cannot create a resource inside the params of another resource).
This commit exports ɵsetInParamsFunction and ɵisInParamsFunction from @angular/core and uses them in FieldMetadataState.runMetadataCreateLifecycle to explicitly detach the lazy creation of form metadata from the parent's reactive params context.

fixes #69620

When a parent form element defines an async validator, its resource's `params`
function needs to evaluate `syncValid()`, which causes unvisited child form
nodes to be lazily instantiated. If any of these lazily instantiated child
nodes also define an async validator, their resource is initialized while the
parent's `params` function is still evaluating. This incorrectly triggers
Angular core's `NG0992` guard (`Cannot create a resource inside the params
of another resource`).
This commit exports `ɵsetInParamsFunction` and `ɵisInParamsFunction` from
`@angular/core` and uses them in `FieldMetadataState.runMetadataCreateLifecycle`
to explicitly detach the lazy creation of form metadata from the parent's reactive
`params` context.

fixes angular#69620
@ngbot ngbot Bot added this to the Backlog milestone Jul 2, 2026
Comment on lines +39 to +40
const wasInParams = ɵisInParamsFunction();
if (wasInParams) ɵsetInParamsFunction(false);

@JeanMeche JeanMeche Jul 2, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The alternative I'm thiking of, is that would be done as part of untracked but it would make that function more load bearing than it should.

@JeanMeche JeanMeche marked this pull request as ready for review July 3, 2026 11:18
@JeanMeche JeanMeche requested review from alxhub and leonsenft and removed request for leonsenft July 3, 2026 11:18
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.

Signal Forms: validateStandardSchema + validateHttp on the same field tree throws NG0992

1 participant