jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
33.91k stars 2.78k forks source link

Validation fires using DateTimePicker even with validateOnChange and validateOnBlur set as false #3717

Closed creix closed 1 year ago

creix commented 1 year ago

Bug report

Current Behavior

When field with DateTimePicker is visited it fires the validation of the entire form, even if i have set validateOnChange={false} and validateOnBlur={false} for Formik.

screencast-codesandbox.io-2023.02.13-14_14_39.webm

Expected behavior

The validation don't fire when visiting DatePickers

Reproducible example

https://codesandbox.io/s/laughing-burnell-4wh8s2?file=/src/App.js

Your environment

Software Version(s)
Formik 2.2.9
React 18.2.0
TypeScript
Browser
npm/Yarn
Operating System
anthonylevine commented 1 year ago

This is because you are setting the initial dates to "". This is not a valid value. Set them to null and the issue is resolved.

creix commented 1 year ago

This is because you are setting the initial dates to "". This is not a valid value. Set them to null and the issue is resolved.

Actually the error still remains even with setting initial dates to null.

AhmedAbuelenin commented 1 year ago

@creix You can use validateOnBlur={true} as a workaround and I see it's a better UX.

creix commented 1 year ago

@creix You can use validateOnBlur={true} as a workaround and I see it's a better UX.

I agree with you. My choice was based on the fact that i have a test with an async call to my server so i didn't wanted to send too many requests to the server.

olzhas-kalikhan commented 1 year ago

I'd suggest to keep client validation in validationSchema, and handle server validation with formik.setFieldError. Something like sentRequest(formValues).then(...).catch(err=> setFieldError('field', err)