Skip to content

feat(forms): allow both patching and strict setting of values #10537

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

Merged
merged 1 commit into from
Aug 5, 2016

Conversation

kara
Copy link
Contributor

@kara kara commented Aug 5, 2016

For background, see the discussion here.

Short version:

We are splitting updateValue() into two functions:

setValue(): this works much like updateValue() does now. The value passed must exactly match the structure of the form, and it will throw an error if it receives a superset or a subset of the form. This is what we'd recommend using in most cases since it will not fail silently.

patchValue(): this is a more forgiving function that will do its best to match controls based on the list it is passed. It will not throw for unrecognized control names, so supersets and subsets will both work. This is what you'd use if you want to include extra properties like created_by.

updateValue() itself is deprecated. Note that this is only happening for the updateValue() that existed in RC.4 (for individual form controls), as updateValue() for FormGroups and FormArrays was never released.

Closes #10057

@kara kara force-pushed the patch branch 2 times, most recently from 579a1a4 to ec21761 Compare August 5, 2016 19:11
@kara kara added the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 5, 2016
@@ -539,6 +576,12 @@ export class FormGroup extends AbstractControl {

/** @internal */
_throwIfControlMissing(name: string): void {
if (!Object.keys(this.controls).length) {
throw new BaseException(`
There are no form controls registered with this group yet. If you're using template-driven forms,
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we agreed not to throw this error.

Also, are we still using the term "template-driven"?

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 can change to "ngModel" if that's clearer.

@vsavkin vsavkin added pr_state: LGTM and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 5, 2016
@kara kara force-pushed the patch branch 3 times, most recently from 719eb8c to e1d3905 Compare August 5, 2016 19:33
@kara kara added the action: merge The PR is ready for merge by the caretaker label Aug 5, 2016
@alxhub alxhub merged commit fcafdff into angular:master Aug 5, 2016
@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 Sep 9, 2019
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature(forms): FormGroup updateValue should not throw error for missing control
4 participants