jaredpalmer / formik

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

Formik with Yup is not validating onBlur and onChange #1702

Open prajavk opened 5 years ago

prajavk commented 5 years ago

🐛 Bug report

My form using yup and is not validating onBlur and onChange on . It validates only onSubmit. How to solve this?

Current Behavior

yup validation not triggered onchange of when I submit an invalid form (and the validation errors start showing), then onChange validations start working. As I press a key, the validation takes place immediately. So I must be missing something in this fiddle example.

Expected behavior

Form should show errors messages onBlur of

Reproducible with this example

Here I added 3 fields - name {html input}, email { Field component with custom handler} , password { component handles change event using props }

https://codesandbox.io/s/formik-with-yup-bbgbz

Suggested solution(s)

Please allow validateOnBlur or ValidateOnChange for

Additional context

I saw this closed issue, https://github.com/jaredpalmer/formik/issues/1442 Want to know, how to deal this business use case.

Your environment

Software Version(s)
Formik 1.5.4
React 16.8.6
TypeScript
Browser
npm/Yarn 10.15.0
Operating System windows 7
bricejar commented 5 years ago

Hi,

The codesanbox link is broken.

prajavk commented 5 years ago

Sorry, I corrected it https://codesandbox.io/s/formik-with-yup-bbgbz

joeshub commented 5 years ago

I'm pretty sure you have to add the onBlur listener to your fields. For example

onBlur={formProps.handleBlur}