ngx-formly icon indicating copy to clipboard operation
ngx-formly copied to clipboard

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

Open dummdidumm opened this issue 6 years ago • 7 comments

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 because myControl will 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);
      }
   }

dummdidumm avatar Nov 08 '19 09:11 dummdidumm

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.

aitboudad avatar Nov 08 '19 11:11 aitboudad

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.

dummdidumm avatar Nov 08 '19 12:11 dummdidumm

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

ThibaudAV avatar Mar 11 '23 16:03 ThibaudAV

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.

kenisteward avatar Apr 05 '23 18:04 kenisteward

Hello @aitboudad , any news about formChange output?

ngagua avatar Dec 15 '23 14:12 ngagua

Any updates for this topic?

ThibaudAV avatar Mar 15 '24 17:03 ThibaudAV