jquense / yup

Dead simple Object schema validation
MIT License
22.72k stars 925 forks source link

Accessing sibling param is undefined #2208

Closed iraviguggilam closed 4 months ago

iraviguggilam commented 4 months ago

I'm trying to access the startDate value in endDate whether which one is higher but I'm getting undefined when I'm trying to access using context.parent.startDate

const validateSchema = Yup.object().shape({
    startDate: Yup.date()
      .default(() => new Date())
      .typeError("Please Enter valid Date Format")
      .required("Field is Mandatory"),
    endDate: Yup.date()
      .default(() => new Date())
      .typeError("Please Enter valid Date Format")
      .required("Field is Mandatory")
      .test(
        "start end date logic",
        "End date should be higher than start date",
        (value, context) => {
          console.log(context.parent.startDate);
          console.log(value.toString());
        }
      ),
    //.min(Yup.ref("startDate"), "Minimum Date"),
  });