DEV Community

iraviguggilam
iraviguggilam

Posted on

yup.ref is not working inside the yup.date().min

I have a basic requirement of end date should be greater than start date. I'm using yup schema for error handling for my react application.

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")
.min(Yup.ref("startDate"), "Minimum Date"),
});

sandbbox link: Sandbox link

https://stackoverflow.com/q/78411998/21108268

Top comments (0)