Hello all,
I am using validationSchema and I want to validate a nested object that has a property with type number. When I try to submit the form leaving this field empty, I get an error saying that this field must be a number.
I forked the codesandbox example from #1091 and I changed the social.facebook to number, so you can see the unexpected behavior. This is the updated version https://codesandbox.io/s/w7r17nnxzk
All HTML inputs are strings. Formik does not convert or transform these for you, you have to do that on your own prior to storing them in Formik state. This is a design decision.
In one level objects everything looks fine. I changed email field to number in this example https://codesandbox.io/s/l9581806vz
If I do it on my own, is it possible to combine validationSchema + custom validation or I have to choose one method per form?
I get the problem.
In validateYupSchema, nested empty strings aren't converted to undefined.
for (let k in values) {
if (values.hasOwnProperty(k)) {
const key = String(k);
validateData[key] = values[key] !== '' ? values[key] : undefined;
}
}
Closing due to long inactivity
Most helpful comment
I get the problem.
In validateYupSchema, nested empty strings aren't converted to undefined.
for (let k in values) { if (values.hasOwnProperty(k)) { const key = String(k); validateData[key] = values[key] !== '' ? values[key] : undefined; } }