diff --git a/packages/ui/src/views/Edit/SetDocumentTitle/index.tsx b/packages/ui/src/views/Edit/SetDocumentTitle/index.tsx index fd9662fea..9623c65f1 100644 --- a/packages/ui/src/views/Edit/SetDocumentTitle/index.tsx +++ b/packages/ui/src/views/Edit/SetDocumentTitle/index.tsx @@ -30,14 +30,9 @@ export const SetDocumentTitle: React.FC<{ const title = formatDocTitle({ collectionConfig, - data: { id: '' }, + data: { id: '', [useAsTitle]: field?.value || '' }, dateFormat: dateFormatFromConfig, - fallback: - typeof field === 'string' - ? field - : typeof field === 'number' - ? String(field) - : (field?.value as string) || fallback, + fallback, globalConfig, i18n, }) diff --git a/test/fields/collections/Date/e2e.spec.ts b/test/fields/collections/Date/e2e.spec.ts index 53e78f8b6..9a4acce04 100644 --- a/test/fields/collections/Date/e2e.spec.ts +++ b/test/fields/collections/Date/e2e.spec.ts @@ -85,6 +85,19 @@ describe('Date', () => { await expect(page.locator('.doc-header__title.render-title')).toContainText('August') }) + test('should retain date format in useAsTitle after modifying value', async () => { + await page.goto(url.list) + await page.locator('.row-1 .cell-default a').click() + await expect(page.locator('.doc-header__title.render-title')).toContainText('August') + + const dateField = page.locator('#field-default input') + await expect(dateField).toBeVisible() + await dateField.fill('02/07/2023') + + await expect(dateField).toHaveValue('02/07/2023') + await expect(page.locator('.doc-header__title.render-title')).toContainText('February') + }) + test('should clear date', async () => { await page.goto(url.create) const dateField = page.locator('#field-default input')