DEV Community

SpeedingRoo
SpeedingRoo

Posted on

[novice's stupid error]Why my Formik validation doesn't work

I was trying to learn how to use Formik in a React project of mine, and I was strictly following the official tutorial: https://formik.org/docs/tutorial

I came to the part where validation mechanism was introduced, I thought the idea was that I create a function, GIVE IT ANY NAME I LIKE, specifiy all the rules in this function and then finally return an error object, then this error object will be stored in a formik instance for me to use.

Since formik said let's specify a CUSTOM validation function and ..., I took the liberty of naming it to a custom function with a custom name that I saw fit.

Image description

My validation didn't work.

I thought maybe I put the submit buttons out of the<form></form>range, which I did before, led to the validation failure. It wasn't

After a long time struggling and not finding any useful information online, I gave up on being special and tried to copy EXACTLY what the tutorial did, I named the custom function as: validate instead of validateFunc.

Image description

Worked.

Go back to the tutorial, it said: Image description Another day of wasting a lot of my life on a stupid error

Top comments (0)