final-form / final-form

🏁 Framework agnostic, high performance, subscription-based form state management

Home Page:https://final-form.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

submitErrors unexpectedly disappears when both errors (syncErrors) and submitErrors exist

leannechen opened this issue · comments

Are you submitting a bug report or a feature request?

Bug report

What is the current behavior?

When submitting form with both syncErrors and submitErrors, submitErrors from previous submit unexpectedly disappears without having an updated one.

Steps to reroduce the problem

  1. Create a form with Field A, with validation:
    1. On input change: Check if input value exceed max-length (e.g. 20).
    2. On submit: Check required (i.e. "This field is required" hint).
  2. Create another Field B, with validation:
    1. On submit: Check required.
  3. Submit. All fields should have the "required" error now.
  4. Edit Field A to make the input value exceed max-length, which will result in a field validate error.
  5. Submit again.
  6. Current Result: The "required" error on Field B disappears.

What is the expected behavior?

The "required" error on Field B exists.

What's your environment?

  • "final-form": "^4.20.2",
  • "react-final-form": "^6.5.2",

Other information

See Line 1090:

delete formState.submitErrors;

Here, the submitErrors is deleted before checking hasSyncErrors. If we have any syncError (or errors, to be specific) here, submitErrors will be deleted, and the function will stop executing before generating an updated submitErrors.

However, it is more reasonable that the deleting and re-generating submitErrors codes should be run or not run at the same time, and not the other way in which only deleting occurs without re-generating.

This way, submitErrors won't be unintendedly affected by whether syncErrors exist.