0
votes

Hello I am trying to use Formik + Yup to validate my form. I am stuck with validating the number for the date, but touching any field keeps crashing the app after I add the number field. How do I properly validate the min and max of a number with Yup?

See my codesandbox: https://codesandbox.io/s/ly027lklq7

If you comment out the whole day date field, the app runs as normal.

1

1 Answers

1
votes

Lack of object validation before accessing nested items in touched is causing the issue.

Eg:

...
props.errors.address && props.errors.address.line1 && props.touched.address.line1
...
...
props.errors.dob && props.errors.dob.day && props.touched.dob.day
...

should be,

...
props.errors.address && props.errors.address.line1 && props.touched.address && props.touched.address.line1
...
...
props.errors.dob && props.errors.dob.day && props.touched.dob && props.touched.dob.day
...

Existing validation is working fine.

fixed code in codesandbox: https://codesandbox.io/s/2omxr4jopp