jannikbuschke / formik-antd

Simple declarative bindings for Ant Design and Formik.
https://codesandbox.io/s/github/jannikbuschke/formik-antd-example
MIT License
589 stars 81 forks source link

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

Closed Vincz closed 4 years ago

Vincz commented 4 years ago

At this line : https://github.com/jannikbuschke/formik-antd/blob/df712fff91bfd3e21ef1f8eb8d7397cbae2da0e1/src/form-item/index.tsx#L30 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 ?

jannikbuschke commented 4 years ago

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

Vincz commented 4 years ago

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 !

jannikbuschke commented 4 years ago

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