-
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
FormArray triggers onFormUpdate too early #127
Comments
I've been discussing that with @zakhenry for a while, but I suspect it might be a good idea to deprecate the @4typen are you using it a lot within your app? |
FormArray
triggers onFormUpdate
too early
FormArray
triggers onFormUpdate
too early
@maxime1992 We use it a few times, but we can change it easily i think. So deprecating |
If you patch your form and update a few values, this hook will be called multiple times: 1 time for each updated value. Which is not ideal. Also has a bug here #127 And I've given more details here: #86 (comment)
If you patch your form and update a few values, this hook will be called multiple times: 1 time for each updated value. Which is not ideal. Also has a bug here #127 And I've given more details here: #86 (comment)
https://github.com/cloudnc/ngx-sub-form/releases/tag/v4.0.1 just got release and embed the deprecation of the method :) #129 has been merged into the |
I hadn't noticed this being here until the 4.0.1 update happened. I've been using onFormUpdate in my own code. What I'm not seeing is what should be used in place of it. My cases for using it have been when I want to have other actions happen as a result of a form value changing. |
@CyberBotX instead of it you can simply subscribe to the BUT, I don't think that this hook was a good idea in the first place. If you end up doing things based on some form values, in a lot of cases it'll probably be something you should do in the parent of that component. Forms should only deal with the form value and not manage side effects IMO. Plus, as the hook is not dealing with observables you'd probably have to use But I may be missing some use cases. Would you mind sharing the code of your components using |
A specific example I have is here: https://www.cyberbotx.com/angular/MutePrincess/src/app/Components/data-input.component.ts (if you want to browse up in the source tree, feel free to do so) with the fully running app at https://www.cyberbotx.com/MutePrincess.php In that example, the data input component has a collection of radio inputs, usually when one is selected, nothing special happens in the data input component and the information is passed as-is to the root component. But if the "Other" option is picked, I show a color picker, which is handled differently from all the other colors. Using onFormUpdate was the only thing I could think of at the time. I don't know if subscribing to the valueChanges of the control would be better in this case or not. If you need other examples, I can provide some more. |
I'd definitely encourage you to listen to Closing as the method in question is deprecated PS:
Funny app btw 🙃! |
Refering to https://github.com/cloudnc/ngx-sub-form#dealing-with-arrays i propably found an issue with the initial building of the FormArray.
The method
onFormUpdate(...)
triggers when the form gets prefilled by the data ofgetInitialModel()
. So the FormArray crewMembers seems to be updated at this time. Instead you have to usethis.formGroup.valueChanges.subscribe(...)
aftersuper.ngOnInit()
to correctly watch for changes.The text was updated successfully, but these errors were encountered: