jannikbuschke / formik-antd

Simple declarative bindings for Ant Design and Formik.

Home Page:https://codesandbox.io/s/github/jannikbuschke/formik-antd-example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Display field error on submit even if it has not been touched

Vincz opened this issue · comments

At this line :

const hasError = error !== undefined && isTouched
there is a check to verify if an error must be displayed or not for a given field.

It ensures that the field has been touched before displaying the error.
I think it should also check if the form has been submitted or not as it is quite weird to have no error displayed on submit if the field has not been touched. Sometimes, the validation failed because the field is required.
Perhaps could it be possible to add a way to define the behaviour with an option ?

Hi @Vincz , I think Formik automatically touches all fields on submit. So I am not sure if I understand the issue you are facing.

Hey @jannikbuschke ! Thanks for replying.
Indeed, you are right. The problem occurs when the field is not properly initialised with an initial value. (ie. Not set in Formik initialValues prop). So It's not a problem related to your lib ! Sorry !

Y, I would suggest to always initialise formik values (null is possible I think).