Using Dates in Enterprise Forms
Date Field in the CMS Form Editor
When you add a "Date Field" to a form in the CMS, you can configure several settings:
-
Initial value: Sets the starting value for the date field. The value shown to site visitors depends on your site implementation. You can choose:
- Empty: No initial value is set.
- Specific date: Set a fixed date.
- Offset from "today": Calculate the initial value as a relative offset from the current date when the page is visited.
- Rule: Use a custom initial value rule. For details, see Custom Date Field Initial Value Rule.
-
Date format: Defines the pattern used to specify and validate the date. If left empty, the default date format is used (see below). Supported formats include:
yyyy/MM/ddMM/dd/yyyydd/MM/yyyy
You can use a space, dash (
-), dot (.), or forward slash (/) as the separator between day, month, and year. Typically, a front-end date picker widget is configured to match the date format, allowing users to enter dates in the correct format. The Enterprise Forms demo project includes an example implementation.Info: Starting with version 3.0.1, you can append a time pattern (
HH:mm) to the date format (separated by a space). This enforces time input in addition to the date.
Customizing the Default Date Format in the CMS
Info: This configuration is available from version 1.03.07.
By default, new date fields use the format pattern MM/dd/yyyy. You can change this default pattern with the following steps:
-
In the console, navigate to the
frontend:pluginnode at:/hippo:namespaces/eforms/form/editor:templates/_default_/form -
Add or update the
dateformatproperty with your preferred format pattern (for example,dd/MMM/yyyy). For supported patterns, refer to the Java Date Format Patterns.
To support language-specific formats, add properties named dateformat_<language> for each language (for example, dateformat_en, dateformat_nl, and so on).
Date Field Support in the Site
On the site, the date field is handled by the following class:
com.onehippo.cms7.eforms.hst.model.DateField
You can retrieve the Initial value and Date format for the field from the bean. Any logic or default values for the initial value are supported through this mechanism.