jaredpalmer / formik

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

Formik Yup.string().lowercase() is not working on email validation #3300

Open arslanalidev opened 3 years ago

arslanalidev commented 3 years ago

Bug report

Current Behavior

I had added the Yup.string().lowercase() to convert the input value into the lowercase by default.

Expected behavior

It should convert the input value in the lowercase and show it in the input field.

Reproducible example

https://codesandbox.io/s/formik-codesandbox-template-forked-59h2w?file=/index.js

Your environment

Software Version(s)
Formik ^2.1.4
React 16.13.1
TypeScript
Browser Google Chrome v92.0.4515.131
npm/Yarn 6.14.8
Operating System Windows 10
markni commented 2 years ago

According to #473 discussion, Formik does not use Yup to do any value transformation, it uses Yup for validation only. You have to cast the value to lowercase yourself.

shtefanilie commented 1 year ago

@markni, ok, but then why is it mentioned in the docs that it's transforming it, not just validating?

Transforms the string value to lowercase. If strict() is set it will only validate that the value is lowercase.

Teajey commented 1 year ago

@markni, ok, but then why is it mentioned in the docs that it's transforming it, not just validating?

Yup only transforms values once .cast() is called, and Formik never does. It's a bit confusing/misleading, I've just recently been tripped up by this too. You need to add .strict() to your schema to get .lowercase() to be validated.

Perhaps Formik should call .strict() automatically so that options like .lowercase() aren't complete noops otherwise