jquense / yup

Dead simple Object schema validation
MIT License
22.93k stars 934 forks source link

Accessing sibling param is undefined #2208

Closed iraviguggilam closed 6 months ago

iraviguggilam commented 6 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"),
  });