Skip to content

Commit e330d88

Browse files
authored
Merge pull request #1766 from jacobsfletch/fix/1765
fix: error clearing date field
2 parents d919abb + 420ed67 commit e330d88

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/admin/components/forms/field-types/DateTime/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const DateTime: React.FC<Props> = (props) => {
8989
placeholder={getTranslation(placeholder, i18n)}
9090
readOnly={readOnly}
9191
onChange={(incomingDate) => {
92-
if (!readOnly) setValue(incomingDate.toISOString());
92+
if (!readOnly) setValue(incomingDate?.toISOString() || null);
9393
}}
9494
value={value as Date}
9595
/>

test/fields/e2e.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,18 @@ describe('fields', () => {
374374
url = new AdminUrlUtil(serverURL, 'date-fields');
375375
});
376376

377+
test('should clear date', async () => {
378+
await page.goto(url.create);
379+
const dateField = page.locator('#field-default input');
380+
await expect(dateField).toBeVisible();
381+
await dateField.fill('2021-08-01');
382+
await expect(dateField).toHaveValue('2021-08-01');
383+
const clearButton = page.locator('#field-default .date-time-picker__clear-button');
384+
await expect(clearButton).toBeVisible();
385+
await clearButton.click();
386+
await expect(dateField).toHaveValue('');
387+
});
388+
377389
test('should display formatted date in list view if displayFormat option added to date field', async () => {
378390
await page.goto(url.list);
379391
const formattedDateCell = page.locator('.row-1 .cell-timeOnly');

0 commit comments

Comments
 (0)