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

Allow updateInitialValue to take a model as optional parameter #2943

Closed
dc-p8 opened this issue Aug 9, 2021 · 1 comment · Fixed by #3022
Closed

Allow updateInitialValue to take a model as optional parameter #2943

dc-p8 opened this issue Aug 9, 2021 · 1 comment · Fixed by #3022

Comments

@dc-p8
Copy link

dc-p8 commented Aug 9, 2021

Is your feature request related to a problem? Please describe.
I came across a case where I needed to update the initial value of my form but without updating the current model with the same instance.

Describe the solution you'd like
It would be great if updateInitialValue() could and optional model as parametter.
This should do the trick :

- options.updateInitialValue = () => (options._initialModel = clone(field.model));
+ options.updateInitialValue = (model = null) => (options._initialModel = clone(model ?? field.model));

Describe alternatives you've considered

(this.options as any)._initialModel = {
    ...this.model_initial,
    facturation: {
        ...this.model_initial.facturation,
        production_history: prod
    }
}
this.model = {
    ...this.model,
    facturation: {
        ...this.model.facturation,
        production_history: prod
    }
};

In this context, this.model_initial and this.model doesn't have the same value :

  this.store.pipe(select(/**/)).$.subscribe((v) => {
      const model_string = JSON.stringify(v); // avoid read-only store issues
      this.model = JSON.parse(model_string);
      this.model_initial = JSON.parse(model_string);
  });
@aitboudad
Copy link
Member

PR welcomed!

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

Successfully merging a pull request may close this issue.

2 participants