0

Let's say I need to validate this object:

{
  productionData: {
    manufacturing: {
      productionDate: "2010-01-01"
    },
  },
  salesData: {
    sellingDate: "2009-01-01"
  }
}

I want to compare the sellingDate against productionDate and display an error if the date is earlier. What is the best way to do this? This is a simplified example, I could have the 2 fields nested at very different levels inside the form object.

Is there a way I can access the whole form data from inside the validation schema and reference a specific property?

I know about .refine(), but this would work only if the properties are in the same object.

ghera
  • 16
  • 1
  • 3
  • 1
    Does this answer your question? [How to check confirm password with zod](https://stackoverflow.com/questions/73695535/how-to-check-confirm-password-with-zod) – Souperman Jul 28 '23 at 00:55
  • @Souperman - not really. that answer is only for the case where the 2 properties are nested in the same object, at the same level – ghera Jul 28 '23 at 13:28
  • on second thought, I just tested again and I can indeed use superRefine for a workaround – ghera Jul 28 '23 at 14:04

0 Answers0