-
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
feat(Touched): Add ability for sub form components to mark sub control as touched with an observable #206
feat(Touched): Add ability for sub form components to mark sub control as touched with an observable #206
Conversation
…l as touched with an observable
@@ -75,6 +75,8 @@ export type NgxSubFormOptions<ControlInterface, FormInterface = ControlInterface | |||
formGroupOptions?: FormGroupOptions<FormInterface>; | |||
emitNullOnDestroy?: boolean; | |||
componentHooks?: ComponentHooks; | |||
// emit on this observable to mark the control as touched | |||
touched$?: Observable<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should help a bit with #155 :)
🎉 This PR is included in version 6.0.0-feat-rewrite.10 🎉 The release is available on: Your semantic-release bot 📦🚀 |
could you give me an example of how this functionality works |
@elvispdosreis the change on the public API is the one pointed out in this comment above: #206 (review) So what you can do is create a subject for example and provide in the createForm config the following key |
sorry but I don't understand this implementation, I'm looking for a way for an event to propagate from the parent form to the children |
Same boat here. Is this meant specifically for subforms and their own controls? Would be nice to have some example use cases. |
Here's what happens behind the scenes:
Meaning, we call the So when you create your sub forms, what you can do is pass the options
And any time you emit in |
I think what most people want (including me) is to be able to trigger something like a 'touchedEvent' on the root-form which will automatically propagate down to all sub/childforms. When somebody sees the touched$ of createForm, they will probably think of something like this (doesn't work):
I don't see where this will help propagating onTouched from root to sub-forms (or even sub-forms to sub-forms) without having to declare & bind a 'touched$' property on each component down the whole "form-tree". Would love to see someone forking my stackblitz and wiring it up as intended 👍 |
I tried to use the solution provided here, but it wasn't taking into account the use of
It seems to work properly, even on the new API. Still, it's quite problematic if you are using the new standalone components on angular 15, like myself, since you then need to import this directive on every single form and sub-form component to make it work. I tried to make a stackblitz to show it working using the code sample from this repo as a base, but I couldn't get it to work (missing types for the module 'uuid', even if add the types as dependency). If you anyone wants to mess around with it, feel free to check it here. Edit: Also, I removed the provider from my current solution, but I'm not entirely sure of the purpose of it. It seems to work fine on my end, with my current form though. |
I couldn't make it work, it doesn't propagate to the subforms |
I am still having difficulty using the I don't see a problem with having to declare touch $ in all form and subform, the problem and that I can't make the events to propagate |
No description provided.