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.