Populate Date and Time fields with the current time using a Content Fragment Editor extension in Experience Manager as a Cloud Service
In Adobe Experience Manager as a Cloud Service, the standard Date/Time field in content fragment models remains empty when authors create or edit a content fragment in the new Content Fragment Editor. In the legacy editor, these fields were pre-filled with the current system time, but the new editor leaves them empty and requires authors to enter the value manually. This change affects authoring workflows that depend on default time values. To populate the field automatically, implement a custom field through the Content Fragment Editor UI extensibility framework and set the current time when the field value is empty. To fix this, create, deploy, and test the custom field extension.
Description description
Environment
- Adobe Experience Manager as a Cloud Service (Content Fragment Editor UI extensibility is supported)
Issue/Symptoms
- Date/Time fields in content fragments are empty by default in the new editor.
- Authors must manually enter the current time.
Cause
The new Content Fragment Editor does not auto-fill Date/Time fields by default. To restore this behavior, a custom field must be implemented using the extensibility framework.
Resolution resolution
To populate the current time automatically, follow these steps:
-
Install and update the Adobe App Builder CLI.
- Run
npm install -g @adobe/aio-cli. - Run
aio plugins:update.
- Run
-
Initialize a Content Fragment Editor extension project using the editor template:
- Run
aio app init --template @adobe/aem-cf-editor-ui-ext-tpl.
- Run
-
Implement a custom Date/Time field React component:
- Use the Custom Fields API to register your custom field.
- In your component, check if the field value is empty. If so, set it to the current system time.
- Example:
import { useEffect } from 'react';
export default function CustomDateTimeField({ value, onChange }) {
useEffect(() => {
if (!value) {
onChange(new Date().toISOString());
}
}, [ value, onChange] );
// Render your date/time input here, allowing manual override
}
- Register this component as a custom field for your Date/Time property using the extensibility framework.
-
Deploy your extension to your AEM environment following the standard deployment steps for App Builder extensions.
-
Test the extension:
- Open a content fragment in the new editor.
- Add or edit a Date/Time field and verify it is auto-filled with the current system time.
- Confirm authors can still modify the value as needed.