Skip to content

Function to reset pristine #146

@gitcatrat

Description

@gitcatrat

Situation:

  • some kind of update form is rendered (e.g user profile update page)
  • user hits submit but request is not made because form is pristine
  • user changes an input or two
  • user hits submit, form is not pristine anymore and request is made
  • user hits submit again after response, request is made again

If user submits their changes and it gets acknowledged by server, form is considered pristine again in my book.

Tried something like this but I'm not sure if correct reference reaches form state. Noticed some issues.

function submitForm() {
    // if values are the same, there's
    // no point to make a request
    if (form.isPristine()) return;

    updateEntityOnServer({
      variables: form.values
    }).then(response => {
      // make all values pristine again
      Object.keys(form.pristine).forEach(key => {
        form.pristine[key] = true;
      });
      // other stuff...
    });
  }

Would be great to have something like this:

form.resetPristine();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions