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
Repeating section > add on submit #1970
Comments
that's a mutability issue which was solved by
import clone from 'lodash.clonedeep';
export class FormDialog {
...
constructor(@Inject(MAT_DIALOG_DATA) public data: any) {
this.model = clone(data.model);
this.fields = clone(data.fields);
this.form = new FormGroup({});
} |
Great. The immutable setting solves the issue the touched or dirty state of the fields. I'm still having the problem, that the form value is set twice after the dialog returns the new value, but this seems to be an issue within our app. I can not reproduce this issue with a minimal setup. It behaves correctly. Thanks for the very quick feedback. |
can you show me how you assigned the returned value to the form? |
Sure.
When I suscribe to the value changes of the field array (this.formControl.valueChanges) to log out the new value and I add one item via the dialog, then I get tons of logs. First of all, the fields of the new group are filled one by one (each reflected in one change), then the fields are removed again (one by one) until all fields are gone, then the new emitted value is an empty array and then all values are added again. I'm debugging through the application trying to find the issue. It seems to be related to hide expressions. In the postPopulate handler, the field is removed right after adding it due formly thinking it should be hidden. However, I do not see, why formly wants to hide the controls. Do you have any tips? I'm investigating further. |
I think we can get rid of those unnecessary changes, for now you can rely instead on |
I think I may need a reproduction example of the hide expression behavior, thanks! |
Sure, I'll try to reproduce it in a smaller app asap. |
With the latest release, I no longer experience critical issues. My problem is with the hide expressions is gone and I couldn't reproduce it lately in a smaller app. |
Thanks for the reproduction, I've pushed some fixes lately which solve the emits issue that will be part of the next minor release |
This issue has been fixed and released as part of v5.5.8 release. Please let us know, in case you are still encountering a similar issue/problem. |
Question
We are currently using the repeating sections within our apps. Is there a way to add items to a form array after the user has filled the form for this specific item by still dynamically rendering all the form template stuff via formly?
The user workflow should be the following:
Do you have an example for this kind of workflow?
I tried to get this running by passing the field.fieldArray.fieldGroup (which is the array of field configs of the field array) of a custom field array type to the modal dialog component. There I used those field configs to within a new formly form. On Submit I passed the form value to the field array custom type, where it got added to the complete form via the add method and by providing an initial value.
However, here I got 2 problems:
Is there a better way to tackle this workflow or do you have any suggestions in general? If required, I can create a Stackblitz.
The text was updated successfully, but these errors were encountered: