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

Assigning a new model won't update the custom field model #975

Closed
JorgeSolFerreira opened this issue Jun 5, 2018 · 7 comments · Fixed by #979
Closed

Assigning a new model won't update the custom field model #975

JorgeSolFerreira opened this issue Jun 5, 2018 · 7 comments · Fixed by #979
Labels

Comments

@JorgeSolFerreira
Copy link

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ x] support request

Current behavior
When changing the form model by assigning it to a new object the custom fields won't update its values while the default fields will.
If the model is updated by changing a model property it will updated in the custom fields but not in the default fields.

Expected behavior
Model in custom field should update when assigning a new model.

Minimal reproduction of the problem with instructions

https://stackblitz.com/edit/ngx-formly-ui-bootstrap-2at8wq?file=app/app.component.ts

Please tell us about your environment:
Windows 10, Microsoft Visual Code, yarn

  • Angular version: 5.2.7
  • Browser: [all]
  • Language: [all]

  • Node (for AoT issues): node --version = 9.2.1

@aitboudad
Copy link
Member

it's an expected behavior since angular doesn't track change of property values in case of object but instead it rely on it's reference.
to change a property, we often use spread operator:

    this.model = {
      ...this.model,
     email: 'email',
    }

@JorgeSolFerreira
Copy link
Author

Is there a way to change a property twice? After changing the value for the first time the custom field loses the reference to the model.

https://stackblitz.com/edit/ngx-formly-ui-bootstrap-aj18js?embed=1&file=app/app.component.ts

@aitboudad
Copy link
Member

that's a bug 😃

@aitboudad
Copy link
Member

fixed in 4.4.3

@krish-ram
Copy link

krish-ram commented Jun 29, 2018

Hi @aitboudad
Is it possible to have this fix in Angular 5 too? 3.x versions?

@aitboudad
Copy link
Member

@krish-ram we currently only support one version (which is the latest one), sorry 🙏

@adrigardi90
Copy link

@krish-ram I had the same problem using Angular 5.
Every time I wanted to update the model I had to reset the formGroup too, apart from updating the required field in the model object

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

Successfully merging a pull request may close this issue.

4 participants