Hi I'm again with Yup and formik doubt
I need validate Fromik field array using Yup My fields are like
[{startdate:'',endDate:'',name:''},{startdate:'',endDate:'',name:''}]
The Start/End Dates are Date object Before using Yup and formik i was doing validation to check selected date are already exits like this
const checkDate=(selectedDate)=>{
const isExisting = datas
.filter((data) => data.startDate !== null || data.endDate !== null)
.some(
(data) =>
new Date(data.startDate).toLocaleDateString() === selectedDate ||
new Date(data.endDate).toLocaleDateString() === selectedDate,
);
if (isExisting) {
toast.error('Date already exits');
return false;
}
}
I know this little weird. Some of you may have better option for this .I were doing all form validation manually like this ,After using formik and Yup helped lot.
Coming to point I need to validate date if user selected any ,Validate if selected date exits or not in array .Its formik field array My validation schema is like
export const CheckoutSchema = Yup.object().shape({
Checkout: Yup.array()
.of(
Yup.object().shape({
name: Yup.string().required(),
startDate: Yup.date().required(),
endDate: Yup.date().required(),
}),
)
});
I have checked some git pages and Stack overflow but I don't know will it work on my case here