diff --git a/packages/ra-ui-materialui/src/input/DateTimeInput.spec.tsx b/packages/ra-ui-materialui/src/input/DateTimeInput.spec.tsx
index dda0e08e524..2518e0f38b4 100644
--- a/packages/ra-ui-materialui/src/input/DateTimeInput.spec.tsx
+++ b/packages/ra-ui-materialui/src/input/DateTimeInput.spec.tsx
@@ -180,5 +180,39 @@ describe('', () => {
).not.toBeNull();
});
});
+
+ it('should be displayed if field has been touched multiple times and is invalid', async () => {
+ const onSubmit = jest.fn();
+ render(
+
+
+
+
+
+ );
+ const input = screen.getByLabelText(
+ 'resources.posts.fields.publishedAt *'
+ );
+ fireEvent.change(input, {
+ target: { value: new Date().toISOString() },
+ });
+ fireEvent.blur(input);
+ await waitFor(() => {
+ expect(screen.queryByText('ra.validation.required')).toBeNull();
+ });
+ fireEvent.change(input, {
+ target: { value: '' },
+ });
+ fireEvent.blur(input);
+ fireEvent.click(screen.getByText('ra.action.save'));
+ await waitFor(() => {
+ expect(
+ screen.queryByText('ra.validation.required')
+ ).not.toBeNull();
+ });
+ });
});
});
diff --git a/packages/ra-ui-materialui/src/input/DateTimeInput.tsx b/packages/ra-ui-materialui/src/input/DateTimeInput.tsx
index 50468432aa3..ebe2d01b157 100644
--- a/packages/ra-ui-materialui/src/input/DateTimeInput.tsx
+++ b/packages/ra-ui-materialui/src/input/DateTimeInput.tsx
@@ -15,7 +15,7 @@ import { InputHelperText } from './InputHelperText';
* @param {string} value Date string, formatted as yyyy-MM-ddThh:mm
* @return {Date}
*/
-const parseDateTime = (value: string) => new Date(value);
+const parseDateTime = (value: string) => (value ? new Date(value) : value);
/**
* Input component for entering a date and a time with timezone, using the browser locale