udos86 / ng-dynamic-forms

Rapid form development library for Angular
ISC License
1.32k stars 367 forks source link

Using formModel value setter does not update formControl value #1112

Closed rernens closed 3 years ago

rernens commented 3 years ago

I'm submitting a


[X] Bug / Regression
[ ] Feature Request / Proposal

I'm using


NG Dynamic Forms Version: `12.0.0`

[ ] Basic UI
[ ] Bootstrap UI  
[ ] Foundation UI
[ ] Ionic UI
[ ] Kendo UI
[X] Material  
[ ] NG Bootstrap
[ ] Prime NG

Description

long time user of ng-dynamic-forms i have been using the following approach to fill my forms with values coming from backed :

private modelToForm (  source ) {
    Object.keys( source ).forEach( key => {
      const model = this.formService.findById( key, this.formModel ) as DynamicInputModel ;
      if ( model ) {
        if ( model.type !== 'GROUP' ) {
          model.valueUpdates.next(source[key]);
        } else {
          this.modelToForm( source[key] );
        }
      }
    });

after moving to Angular 10 and ng-dynamic-forms 12.0.0, I have updated my approach to adapt to breaking changes introduced with value updates in more recent versions of ng-dynamic forms :

private modelToForm (  source ) {
    Object.keys( source ).forEach( key => {
      const model = this.formService.findModelById( key, this.formModel ) as DynamicInputModel ;
      if ( model ) {
        if ( model.type !== 'GROUP' ) {
          model.value = source[key];
        } else {
          this.modelToForm( source[key] );
        }
      }
    });

Value uodate is well reflected in the model variable after model.value = source[key] is executed. After the forEach loop ends, inspection of this.formModel shows that values are not updated. Value updates are not reflected in the formgroup and do not show in the UI. No errors are produced in the console