final-form / react-final-form

🏁 High performance subscription-based form state management for React
https://final-form.org/react
MIT License
7.39k stars 481 forks source link

Fields are not visited after failed submit (only touched) #760

Open swarthy opened 4 years ago

swarthy commented 4 years ago

Are you submitting a bug report or a feature request?

bug report

What is the current behavior?

Fields marked only as "touched" on form submit with validation errors.

What is the expected behavior?

Fields marked both "touched" and "visited" on failed form submit.

Sandbox Link

https://codesandbox.io/s/epic-night-ckefb

What's your environment?

Chromium 80.0.3987.132 "final-form": "4.18.7" "react": "16.12.0" "react-final-form": "6.3.5"

Other information

Field marks "visited" when it got focused and "touched" when got and lost focus. If that's correct then same should happens on failed submit.

callmeberzerker commented 4 years ago

Same but not same. The current behavior is fine IMO. Why are you really needing this?

swarthy commented 4 years ago

In my form I display error when user focused invalid field, so I use "visited" flag instead of "touched". example Also I expect (same as https://github.com/final-form/react-final-form/issues/186) that on failed submit "touched" (means "focused & leaved") (and "visited" as it means "focused") should become true. If touched ("focused & leaved") === true why "visited" ("focused") === false? There is nothing about this custom behavior for failed validation in docs.

touched true if this field has ever gained and lost focus. false otherwise. visited true if this field has ever gained focus. false otherwise.

So, this behavior is not transparent IMO. P.S. I fixed my form with meta.visited || meta.touched but it seems weird.

swarthy commented 4 years ago

If that behavior is fine, then "touched" should be documented as "field was focused & leaved OR failed validation"