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

Reset the form and update the model with the new values #3862

Open
Lunatig opened this issue Feb 5, 2024 · 0 comments
Open

Reset the form and update the model with the new values #3862

Lunatig opened this issue Feb 5, 2024 · 0 comments
Labels

Comments

@Lunatig
Copy link

Lunatig commented Feb 5, 2024

i have a problem with reseting the form and update the model with the new values.

  1. receive data from the server for the form and fill out the form.
  2. make changes to the data.
  3. send the data to the server.
  4. The server may not accept the changes and return data with values different from those sent.
  5. need to place these new values into the current form.

Is there any way to reset the model without activating expressions? I have a rather large form with many expression dependencies, and when I set my model value to a new one, expressions start recalculating one by one. This can lead to unwanted results. For example, if I set

.subscribe({
  next: (savedOperation: Operation) => {
    this.model = savedOperation;
  });

some values become undefined faster than others, and expressions for the first property of the new object will calculate before other values are replaced.

Using this.options.resetModel?.(savedOperation); does not clear the inputs. This method replaces only the provided values and returns the values for inputs cleared just before.

The only way I can achieve a full form value replacement is by using setTimeout with a delay. However, this method makes my form blink:

this.currentOperation = {};

setTimeout(() => {
  this.model = cloneDeep(savedOperation);
  this.options.resetModel?.();
  this.form.markAsPristine();

  this.isFormProcessing$.next(false);
}, 100);

Is there a more efficient way to update the form model without triggering expression recalculations before full model replace or experiencing the form blinking issue?

Thank you for any assistance you can provide

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

No branches or pull requests

1 participant