udos86 / ng-dynamic-forms

Rapid form development library for Angular

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using formModel value setter does not update formControl value

rernens opened this issue · comments

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