ngx-formly
ngx-formly copied to clipboard
Add (formChange) Output Binding to get notified of form structure changes
I want to get notified whenever the structure of the form changes.
Use case:
- The form is not initialized at the start, but only after user clicks a button.
- I want to subscribe to changes (validity and value) of a specific control:
this.form.controls.myControl.valueChanges... This will fail if I do this too early becausemyControlwill only exist after the formly form initialized itself.
So far I have not found a good solution to get noticed when formly changed the structure of the form. I therefore propose a new Output binding formChange:
Proposal:
export class FormlyForm implements ... {
@Output()
formChange = new EventEmitter<FormGroup | FormArray>();
...
ngOnChanges(simpleChanges: SimpleChanges) {
... // existing implemtation
// new:
if (changes.fields || changes.form) {
this.formChange.next(this.form);
}
}
That's on the plan but I'd use fieldChange to make consistent with the provided one through the option.
The implementation would require some time as we're currently working on the next major version v6 so let me know if you're looking for a workaround.
Thanks for the info, looking fourward to it :)
The current workaround for me is to extend the FormlyForm Component, copypaste the decorator and add mentioned code. I'm fine with that.
Hi 👋 I also have the same need "Callback after the form is ready" As v6 is released I would like to know if there is a solution? Because I would like to add a spinner when the form is long to build 🙏
Thanks for your help
Hi 👋 I also have the same need "Callback after the form is ready" As v6 is released I would like to know if there is a solution? Because I would like to add a spinner when the form is long to build 🙏
Thanks for your help
Is the build long (e.g. you have tons of fields) or have you been able to 0 out the rendering is what is taking long? Wondering because I've not come into this issue yet so I wanna wrap my head around it.
Hello @aitboudad , any news about formChange output?
Any updates for this topic?