ngx-formly / ngx-formly

📝 JSON powered / Dynamic forms for Angular
https://formly.dev
MIT License
2.79k stars 559 forks source link

Add (formChange) Output Binding to get notified of form structure changes #1912

Open dummdidumm opened 4 years ago

dummdidumm commented 4 years ago

I want to get notified whenever the structure of the form changes.

Use case:

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);
      }
   }
aitboudad commented 4 years ago

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.

dummdidumm commented 4 years ago

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.

ThibaudAV commented 1 year ago

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

kenisteward commented 1 year ago

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.

ngagua commented 9 months ago

Hello @aitboudad , any news about formChange output?

ThibaudAV commented 6 months ago

Any updates for this topic?