Yup: date().required("Required")

Created on 15 Aug 2019  路  1Comment  路  Source: jquense/yup

When adding a string parameter to required() ex. 'required("Required")' for yup.date the parameter is not added to the validation object when validate() is ran.

expected: Required
actual: effectiveDate must be a date type, but the final value was: Invalid Date (cast from the value "").

Yup Object used

export const = DateSchema = Yup.object().shape({
  date : Yup.object().shape({
    effectiveDate: Yup.date().required("Required"),
    expirationDate: Yup.string().required('Required'),
  })
})

Also expirationDate's error message in the validation object shows "Requred" as expected.

Most helpful comment

The issue is resolved. I needed to add .nullable().

Yup.date().required("Required").nullable().

>All comments

The issue is resolved. I needed to add .nullable().

Yup.date().required("Required").nullable().

Was this page helpful?
0 / 5 - 0 ratings