-
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
get model updates when invalid #221
Comments
Hi @codehunter13 👋 What you said is correct ✔️ When using the And when using If this is in your case a 1 time thing and you don't really need to reuse this behavior then I'd do what you said and have a custom event. If it's a recurring pattern on your side it may be worth creating a new class in your project, extends @zakhenry this is the first time someone mention this so maybe a little bit early to really consider the use case which has an easy workaround but here's the open question: May it be worth to have some config passed when we create the form to say whether it should emit or not when the form is invalid? 🤔 It'd be fairly easy to implement I reckon but I'm not 100% sure it makes sense to have this supported. @codehunter13 another suggestion if you want to skip the custom event emitter: If you need to access the form value (valid or invalid) from the parent component you can simply add a template reference on your form component and access the formgroup instance like this:
and then using |
i've already extended NgxRootFormComponent and added a second eventemitter. |
@codehunter13 I have the same need |
Hello 👋 There's one problem I can think of and have no idea how to go around: While it'd work fine on the root level because it'd be as easy as creating an output and instead of creating a new event emitter for it, set it to Can anyone think of a better way to achieve this? |
Hi, it is not really necessary to add this Event Emitter in the subforms, if the root forms have it, it is enough. It is my POV and it would work for me if I implemented a strategy as fast as possible in the root forms. In previous versions, this need was solved with this:
Now I don't see anything unreasonable to add an Event Emitter in the root forms that is emitting the value of the form every time that one of its controls changes. In my opinion, the subforms do not need to be changed. I hope it helps. |
Thanks for sharing your POV. On
I think it may be quite confusing to have an event on a root form to get the form state even if it's invalid but it'll only be the case for the top part of the form, not the children. If that's really what you want, I don't think we need to include anything into ngx-sub-form itself to do that, all you have to do is add an output on your root form with the following code:
Does is seem reasonable to you? having any kind of wrapper to do that from ngx-sub-form wouldn't help much as you've have at least to declare the output yourself (otherwise Angular compiler wouldn't be happy). It isn't much longer to assign Note: I haven't checked but from memory |
Hi, you gave me a great idea with Here is the implementation I did to solve my need:
Conclusion: There is no need to change anything in the library, my problem was more associated to the lack of knowledge about the latest version. Thank you very much for your cooperation. |
Hi,
Is there a buildin way to get the form model in the container component when the form is invalid?
if i get it correctly, dataOutput only fires when the form is valid?
my case:
all field are required
initial values send from container to form: null ,null,null => form is invalid
user change a value: "A", null, null => form still invalid
container components gets a value from another service that must be send to the form.
So i need to send "A", newvalue, null from container to form
But it doesnt know there is value A in the first field.
i can add my own eventemitter to the form but just want to be sure there isnt something buildin.
Thx in advance
The text was updated successfully, but these errors were encountered: