Visitar URL original
feat(forms): introduce extractValue utility for signal forms by kirjs · Pull Request #67063 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20260317010253/https://github.com/angular/angular/pull/67063
Skip to content

feat(forms): introduce extractValue utility for signal forms#67063

Merged
mattrbeck merged 4 commits intoangular:mainfrom
kirjs:extract
Mar 16, 2026
Merged

feat(forms): introduce extractValue utility for signal forms#67063
mattrbeck merged 4 commits intoangular:mainfrom
kirjs:extract

Conversation

@kirjs
Copy link
Contributor

@kirjs kirjs commented Feb 13, 2026

Adds extractValue utility to the forms/signals/compat package. This function extracts the raw value from a FieldTree, recursively unwrapping AbstractControl instances.

It also allows to filter out only dirty/touched/enabled values or their combination to help reproduce ReactiveForms behavior.

Key Features

  • Unwraps AbstractControls: Automatically resolves any AbstractControl instances in the FieldTree to their underlying values (essential for compatForm).
  • Structured Filtering: Adds ExtractFilter to selectively extract fields based on state (dirty, touched, enabled).
  • Array Preservation: Unlike Reactive Forms which removes filtered array items, extractValue preserves index positions by setting filtered items to undefined.

Usage

const f = compatForm(signal({first: 'Alice', last: new FormControl('Doe')}));
extractValue(f); // {first: 'Alice', last: 'Doe'}

// With filter
extractValue(f, {touched: true});

@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: forms labels Feb 13, 2026
@ngbot ngbot bot added this to the Backlog milestone Feb 13, 2026
@kirjs kirjs force-pushed the extract branch 2 times, most recently from 94bd1d5 to f5007a4 Compare February 17, 2026 18:58
@AndrewKushnir AndrewKushnir requested review from leonsenft and removed request for AndrewKushnir and devversion February 17, 2026 19:19
@pullapprove pullapprove bot requested a review from devversion February 17, 2026 19:19
It's a helper function that takes a form, and extrasts it's value unwrapping compat values and also allowing to filter them.
Drop unnecessary casts + cleanup
thoroughly tests both propagation directions
});
});

it('should handle enabled: false filter', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you forgot to delete this test, since there's a duplicate one under the new group.

return value !== undefined;
}

function isKeyedResult(value: [string, unknown] | undefined): value is [string, unknown] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about the removed hasChildren function. I don't think this type guard nor the one above adds anything that a simple check !== undefined wouldn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dropped


for (let i = 0; i < arrayValue.length; i++) {
const child = record[i];
if (!isFieldTreeNode(child)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In what case does an array field in a FieldTree not contain FieldTrees children?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was overly defensive here, should be safe to drop if I update type

Minor test and type cleanup
@kirjs kirjs requested a review from leonsenft February 27, 2026 01:11
Copy link
Contributor

@leonsenft leonsenft 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

@kirjs kirjs added action: merge The PR is ready for merge by the caretaker labels Mar 16, 2026
@ngbot
Copy link

ngbot bot commented Mar 16, 2026

I see that you just added the action: merge label, but the following checks are still failing:
    failure status "pullapprove" is failing
    pending missing required labels: target: *
    pending 1 pending code review

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken main, please try rebasing to main and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

1 similar comment
@ngbot
Copy link

ngbot bot commented Mar 16, 2026

I see that you just added the action: merge label, but the following checks are still failing:
    failure status "pullapprove" is failing
    pending missing required labels: target: *
    pending 1 pending code review

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken main, please try rebasing to main and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@kirjs kirjs added target: patch This PR is targeted for the next patch release target: minor This PR is targeted for the next minor release labels Mar 16, 2026
@kirjs kirjs added target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Mar 16, 2026
@mattrbeck mattrbeck merged commit a94958b into angular:main Mar 16, 2026
29 of 31 checks passed
@mattrbeck
Copy link
Member

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 detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants