Well, I'm new with react, but I'm trying to validate two dates (im using dayjs for the dates).
I want to check that a date in a field "to" doesnt come before another date in field "from".
I have the following in a file called regex.js:
export const validateFromBeforeTo = (values) => {
const message = "error: date in field 'to' cant be before date in field 'from'";
console.log((dayjs(values[0].from).diff(dayjs(values[0].to)) < 0 )? "false" : "true");
return (dayjs(values[0].from).diff(dayjs(values[0].to)) < 0 )? undefined : message
}
(I know it's not perfect since i have to loop, but for now is just to make it work)
And I have the following in the test.js file
<FormTab label="MyForm">
<CustomTitleField title="Disponibilità" />
<ArrayInput source="availability" label="avail" validate={validateFromBeforeTo}>
<SimpleFormIterator>
<DateTimeInput label="Da" source="from" showTime validate={validateFifteenMin()} />
<DateTimeInput label="A" source="to" showTime />
</SimpleFormIterator>
</ArrayInput>
</FormTab>
My problem is that if I console.log the result, when i change the dates it prints correctly, but it does NOT shows errors in the form.
What I'm doing wrong?