final-form / final-form/react-final-form

meta.error incorrect for fields when changing validator despite adding key to field as per example. See sandbox

Open
#980 2 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.4k
Forks
497
PR merge metrics
No merged PRs in 30d

Description

### Are you submitting a **bug report** or a **feature request**?

Bug Report

### What is the current behavior?

Based on the documentation, validate functions for fields can be changed but a unique key must be added to the Field to ensure the correct validate function is used.
This works and the overall error state is updated correctly.
Unfortunately, the meta.error for the render component of the field with the validator gets a previous error state making it incorrect when trying to display the error.

### What is the expected behavior?
The render component for a Field being parsed the correct error in meta.error as per the overall error state

### Sandbox Link

The issue is simple to reproduce with this example. Note that the error rendered for the Field is different from the error for the field in the formState - it is the previous error.

[Sandbox link reproducing the issue](https://codesandbox.io/embed/changing-field-level-validators-forked-f8twbd?fontsize=14&hidenavigation=1&theme=dark)

### What's your environment?

final-form: 4.20.6
reat-final-form: 6.5.8
react: 16.14
react-dom: 16.14

### Other information

If I downgrade react-final-form to 4.1.0, the issue is resolved. Any version above this has the issue. Our initial investigation indicated that any version above uses useField inside Field and 4.1.0 doesn't.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.