resolvers icon indicating copy to clipboard operation
resolvers copied to clipboard

Yup validation schema on nested object presenting error (with ref to issue #63)

Open Biz-e-Services opened this issue 4 years ago • 1 comments

Hi. Had same issue as #63 and was resolved, but to only two levels deep of object. I have...

const NewPackSchema = yup.object().shape({
  reference: yup.string().required("Reference is a required field"),
  createdById: yup.string().required("Created by is required"),
  requestDetail: yup.object().shape({
    reference: yup.string().required("REQ Reference is a required field"),
    applicantDetail: yup.object().shape({
      fullName: yup.string().required("Fullname is a required field"),
    }),
  }),
});

and get error of TypeError: Cannot read properties of undefined (reading 'message')

on ...

<TextField
  label="Fullname"
  {...register("requestDetail.applicantDetail.fullName")}
  error={errors.requestDetail?.applicantDetail?.fullName ? true : false}

// also tried error={errors.requestDetail.applicantDetail?.fullName ? true : false}
/>;

... help would be appreciated, thanks.

Biz-e-Services avatar Jul 22 '22 07:07 Biz-e-Services

please follow the issue template.

bluebill1049 avatar Jul 22 '22 11:07 bluebill1049