-
Notifications
You must be signed in to change notification settings - Fork 33
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
How can we propagate formGroup.reset() to every subform. #59
Comments
I found some stackoverflow input here. I guess this would propagate down the tree if implemented. However I feel like ControlValueAccessor should implement a callback for resetting(); |
Hi @andreElrico 👋 Indeed this looks like a bug to me. If nobody can pick that one up I'll take a look once I'm done with the form arrays :) Although for now you you just create a method "reset" in the component and patch it with null values (or your default ones). Still I agree it's not convenient and should be fixed 👍 |
I think that if you also set the values to null and patch them from the top level parent then reset would work as the default value (that is reused when you do reset!) would be null. But yeah I'll focus in the next few days on shipping the form arrays PR as it's getting pretty huge and I'd rather focus on that one for now. Hopefully that one (reset) should be simpler I think :) If you feel like having a go @andreElrico feel free to give it a try and raise a PR if you come to a good implementation. And even in the case where you don't manage to go through we could have a look and discuss your PR :) Oh and I almost forgot: Thanks for all the stackblitz repro you've been doing it's really helpful! |
I will try to deep dive into the source and see what I can do. :) |
Just some brainstorming:
|
Good idea! Brainstorming is cheaper than code refactoring =)
I remember having the same thought few months ago (cf ngx-sub-form/projects/sub-form/src/lib/sub-form.component.ts Lines 97 to 106 in 8593c10
And then realized it wouldn't be that easy 😅
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 think it wouldn't be an issue as an |
Actually, having second thoughts.
I think that one way of achieving that would be to have a provider set on the But so far we've managed to not have anything to inject that'd have to be in the constructor and thus components extending ngx sub forms would have to inject the required services and pass them to super =(... Not sure what's the best option here. @zakhenry any idea? |
I would go ng-style:
I dont know If I got you correctly on that, but I think we dont have to provide it on the highest level, I a special option is desired app wide, the user can of course root inject it in |
@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. |
|
Hello all <3,
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.The text was updated successfully, but these errors were encountered: