Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(forms): allow patchValue method of FormGroup and FormArray classes to skip null values #40534

Closed
wants to merge 1 commit into from

Conversation

AndrewKushnir
Copy link
Contributor

Prior to this commit, the patchValue of the FormGroup and FormArray classes used to throw an exception
when the value argument contained a data structure that has null or undefined as a value for a field
that represents an instance of FormGroup or FormArray (for FormControl it's not a problem, since it
doesn't have nested controls), since the patchValue method tried to iterate over provided value to
match current data structure.

This commit updates the patchValue logic in FormGroup and FormArray classes to just ignore null and
undefined values (without any changes to corresponding FormGroup and FormArray instances). This
behavior is inline with the patchValue method goal of "doing its best to match the values to the correct controls"
(quote from docs).

Fixes #36672.
Fixes #21021.

PR Type

What kind of change does this PR introduce?

  • Bugfix

Does this PR introduce a breaking change?

  • Yes
  • No

@AndrewKushnir AndrewKushnir added type: bug/fix state: WIP area: forms target: patch This PR is targeted for the next patch release labels Jan 23, 2021
@ngbot ngbot bot added this to the Backlog milestone Jan 23, 2021
@google-cla google-cla bot added the cla: yes label Jan 23, 2021
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Fairly simple fix - LGTM.

I think there is a typo in the commit message:

...iterate over provided value...

->

...iterate over provided values...

Also (NITs):

  • I prefer to add () when mentioning functions in commit messages (e.g. patchValue() rather than patchValue) since it helps when scanning the text.
  • The bit in brackets (for FormControl it's not a problem, since it doesn't have nested controls) could be moved to its own sentence after the end of this sentence, since it kind of gets in the way of the main description of the commit.

…` classes to skip `null` values

Prior to this commit, the `patchValue()` of the `FormGroup` and `FormArray` classes used to throw an exception
when the `value` argument contained a data structure that has `null` or `undefined` as a value for a field
that represents an instance of `FormGroup` or `FormArray` (for `FormControl` it's not a problem, since it
doesn't have nested controls), since the `patchValue()` method tried to iterate over provided values to
match current data structure.

This commit updates the `patchValue()` logic in `FormGroup` and `FormArray` classes to just ignore `null` and
`undefined` values (without any changes to corresponding `FormGroup` and `FormArray` instances). This
behavior looks inline with the `patchValue()` method goal of "doing its best to match the values to the
correct controls" (quote from docs).

Fixes angular#36672.
Fixes angular#21021.
@AndrewKushnir AndrewKushnir added action: presubmit The PR is in need of a google3 presubmit and removed state: WIP labels Jan 24, 2021
@AndrewKushnir AndrewKushnir marked this pull request as ready for review January 24, 2021 21:45
@AndrewKushnir
Copy link
Contributor Author

Presubmit.

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker and removed action: presubmit The PR is in need of a google3 presubmit labels Jan 25, 2021
jessicajaniuk pushed a commit that referenced this pull request Jan 25, 2021
…` classes to skip `null` values (#40534)

Prior to this commit, the `patchValue()` of the `FormGroup` and `FormArray` classes used to throw an exception
when the `value` argument contained a data structure that has `null` or `undefined` as a value for a field
that represents an instance of `FormGroup` or `FormArray` (for `FormControl` it's not a problem, since it
doesn't have nested controls), since the `patchValue()` method tried to iterate over provided values to
match current data structure.

This commit updates the `patchValue()` logic in `FormGroup` and `FormArray` classes to just ignore `null` and
`undefined` values (without any changes to corresponding `FormGroup` and `FormArray` instances). This
behavior looks inline with the `patchValue()` method goal of "doing its best to match the values to the
correct controls" (quote from docs).

Fixes #36672.
Fixes #21021.

PR Close #40534
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: forms cla: yes target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Form patchValue method throws unnecessary error FormGroup.patchValue should ignore null arrays
3 participants