Formik: validationSchema nested object using type:number unexpected behavior

Created on 21 Nov 2018  路  4Comments  路  Source: formium/formik

馃悰 Bug report

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

stale

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; } }

All 4 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

outaTiME picture outaTiME  路  3Comments

jordantrainor picture jordantrainor  路  3Comments

jaredpalmer picture jaredpalmer  路  3Comments

emartini picture emartini  路  3Comments

giulioambrogi picture giulioambrogi  路  3Comments