bmvantunes / youtube-2020-june-multi-step-form-formik

A repository with a multi-step form using Formik, Yup and Material-UI
https://youtu.be/l3NEC4McW3g
MIT License
100 stars 68 forks source link

Sequential validation after onBlur on required fields #7

Closed 3runoDesign closed 4 years ago

3runoDesign commented 4 years ago

After the 'OnBlur' event in any mandatory field ... all other fields with any validation are triggered as invalid.

One of my approaches was to customize my fields for these types of forms...

...
onBlur={() => helpers.setTouched(true)}
...

But I really don't know what the best approach would be!.

https://codesandbox.io/s/polished-dew-8ns0u?file=/src/pages/index.tsx Such an exception occurs only in subsequent steps.

Thanks!!

bmvantunes commented 4 years ago

That example you sent seems to be working correctly. I also was not able to trigger any exception playing with your code :)

The only interesting thing I saw is that you are probably trying to play with FormArrays by the name of your fields [lastName] - if you want that, you want to check: https://formik.org/docs/api/fieldarray

3runoDesign commented 4 years ago

is that the first stage has to be the second stage. I will change here later.

3runoDesign commented 4 years ago

Update https://codesandbox.io/s/polished-dew-8ns0u?file=/src/pages/index.tsx

bmvantunes commented 4 years ago

Any news regarding this one? :)

3runoDesign commented 4 years ago

@bmvantunes the solution was to reset the touched fields for each new step.

helpers.setTouched({});

https://codesandbox.io/s/polished-dew-8ns0u?file=/src/pages/index.tsx:4143-4176