question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can we propagate formGroup.reset() to every subform.

See original GitHub issue

Hello all ❤️,

here I forked a Stackblitz of yours.

When we click on the RED reset-button. The root-Forms values are being cleared but the values in the subforms still remain.

How can we reset() the whole thing? Should the root level form and all subforms be in total sync? two-way-bindings? Should a new method propagateReset() be introduced? That resets itself and all sub-forms down the tree.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
zakhenrycommented, Jun 19, 2019

@andreElrico @maxime1992 yep I think I agree that an injection token is probably the best option, remember that it can be managed in providers, not the constructor.

1reaction
andreElricocommented, Jun 19, 2019

I think that’s a good idea. We could have the default behavior provided at the highest level and then people might just override it when needed.

I would go ng-style:

  1. register Token. https://github.com/angular/components/blob/8b5c0f12c823a16bdf3d4bcd767d0c42c6b0e870/src/material/form-field/form-field.ts#L93

  2. inject in every ngx-sub-form class. https://github.com/angular/components/blob/8b5c0f12c823a16bdf3d4bcd767d0c42c6b0e870/src/material/form-field/form-field.ts#L272

  3. If no dependency is resolved setup the “default” one. https://github.com/angular/components/blob/8b5c0f12c823a16bdf3d4bcd767d0c42c6b0e870/src/material/form-field/form-field.ts#L282

I dont know If I got you correctly on that, but I think we dont have to provide it on the highest level, rather if no option is provided we fall back to a default.

I a special option is desired app wide, the user can of course root inject it in app.module.ts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I reset a group of formControls in Reactive Forms?
I have table with many rows that's generated with a ngFor loop. When the user clicks on a row or group of rows,...
Read more >
Angular: Nested Reactive Forms Using ... - Medium
In this post, we will see how to implement nested reactive forms using composite control value accessors(CVAs). Kara Erickson of the Angular Core...
Read more >
Working with Angular 4 Forms: Nesting and Input Validation
Forms in Angular applications can aggregate the state of all inputs that are under that form and provide an overall state like the...
Read more >
Angular Development #9 - Reusable Sub-Forms - Intertech
Learn how to build reusable sub-form sections that can be shared between many forms in the latest post of our series on Angular...
Read more >
Real world example for angular reactive forms - codebits
I won't cover each part of the final product in this tutorial, ... We can provide a validator function to each formGroup in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found