Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscribe to fieldChanges and get no change from expressionProperties #2350

Closed
GlauberF opened this issue Jul 3, 2020 · 4 comments
Closed

Comments

@GlauberF
Copy link

GlauberF commented Jul 3, 2020

Description
within a type(table) I need to be notified when the field changes, using formly's expressionProperties property.
my implementation in the field:
Captura de Tela_selecionar área_20200703164118

I tried to use the following listener within the type (table):

this.options.fieldChanges.subscribe(el => {
     console.log('fieldChanges', el);
});

however, I am only notified when there is a change of type "hidden"
Captura de Tela_selecionar área_20200703163335

I don't know if it's a bug, but I believe it should be notified or if there is another way to hear these changes made by expressionProperties

Your Environment

Angular CLI: 10.0.1
Node: 12.18.1
OS: linux x64

Angular: 10.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router, service-worker
Ivy Workspace: Yes

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.1000.1
@angular-devkit/build-angular      0.1000.1
@angular-devkit/build-optimizer    0.901.1
@angular-devkit/build-webpack      0.1000.1
@angular-devkit/core               10.0.1
@angular-devkit/schematics         10.0.1
@angular/cdk                       10.0.1
@angular/cli                       10.0.1
@angular/flex-layout               9.0.0-beta.29
@angular/material                  10.0.1
@angular/material-moment-adapter   10.0.1
@ngtools/webpack                   10.0.1
@nguniversal/builders              10.0.1
@nguniversal/common                10.0.1
@nguniversal/express-engine        10.0.1
@schematics/angular                10.0.1
@schematics/update                 0.1000.1
rxjs                               6.5.5
typescript                         3.9.6
webpack                            4.43.0

formly                               5.7.1
@GlauberF GlauberF added the bug label Jul 3, 2020
@dottodot
Copy link

dottodot commented Jul 5, 2020

I have a similar issue as I want to render a template that contains a value from the form but expressionProperties doesn't update when the model changes.

            fieldGroup: [
              {
                type: 'html-template',
                templateOptions: {
                  template: '',
                },
                expressionProperties: {
                  'templateOptions.template': (
                    model,
                    formState: any,
                    field: FormlyFieldConfig
                  ) => {
                    // This needs to update when the name field is changed.
                    return `<p><strong>${
                      field.parent.parent.model.name
                        ? field.parent.parent.model.name.toUpperCase()
                        : ''
                    }</strong></p>`;
                  },
                },
              },
            ],

@aitboudad aitboudad added enhancement and removed bug labels Jul 5, 2020
@aitboudad
Copy link
Member

@dottodot not related to this issue, please create a new issue with a reproduction using our starter example https://stackblitz.com/edit/ngx-formly-ui-bootstrap

@aitboudad
Copy link
Member

aitboudad commented Jul 14, 2020

This issue has been fixed and released as part of v5.9.0 release.

The fieldChanges now include expressionChanges event which emit the following object:

{
  field,
  type: 'expressionChanges',
  property: 'templateOptions.label', // expression property
  value, // expression value
}

Please let us know, in case you are still encountering a similar issue/problem.
Thank you!

@GlauberF
Copy link
Author

thank you very much @aitboudad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants