react-final-form icon indicating copy to clipboard operation
react-final-form copied to clipboard

Validation error not cleared after unmounting Field with validate

Open aczekajski opened this issue 5 years ago • 2 comments

Are you submitting a bug report or a feature request?

Bug report or request for making clear in docs that doing the following is forbidden

What is the current behavior?

  1. Use the Field with the same name more then once and specify some validation on one of them
  2. Unmount only the one with validate prop on it
  3. See the validation error never being cleared nor changed even if you change the field value

On the following example you can mount and unmount Field with validate on it by using checkbox. Below the errors, valid and values of form are shown. https://codesandbox.io/embed/react-final-form-unmounting-validation-bug-doocv

What is the expected behavior?

Unmounting Field should also clear validation errors previously produced by validate on this Field.

Additional info: desired behaviour can be observed if you unmount all occurences of Field with the same name.

Sandbox Link

https://codesandbox.io/embed/react-final-form-unmounting-validation-bug-doocv

What's your environment?

As seen in CodeSandbox example: "final-form": "4.8.15", "react": "16.9.0", "react-dom": "16.9.0", "react-final-form": "6.3.0"

Run on Chrome 74, Windows.

Other information

Desired behaviour can be observed if you unmount all occurences of Field with the same name.

aczekajski avatar Sep 04 '19 20:09 aczekajski

I have found a problem similar to this. I'm changing a field's validate function (to make it required/not required) and the old validation remained after changing the validate function, the field had to get focus before clearing out the old errors. I can confirm that I was also changing the key as per the documentation.

highflying avatar Oct 15 '19 09:10 highflying

@highflying Have you tried to reach something like this? https://codesandbox.io/s/agitated-david-qzyq98?file=/src/App.tsx

farshmachine avatar Jun 23 '23 05:06 farshmachine