Feature: #106681 - Support relative date formats in DateRange validator
See forge#106681
Description
The
Date validator of the form extension now supports relative
as well as absolute dates in Y- format.
This allows form integrators to define dynamic date constraints that are evaluated at runtime, such as ensuring a date of birth is at least 18 years in the past or that a date is in the future.
The following relative expressions are supported and follow the syntax of
strtotime:
- Named dates:
today,now,yesterday,tomorrow - Relative offsets:
-18 years,+1 month,-2 weeks,+30 days
These expressions can be used in the
options. and
options. properties of the
Date validator.
Example
Ensure that a date of birth is at least 18 years in the past:
type: Date
identifier: date-of-birth
label: 'Date of birth'
validators:
-
identifier: DateRange
options:
maximum: '-18 years'
Ensure that a date is in the future:
type: Date
identifier: event-date
label: 'Event date'
validators:
-
identifier: DateRange
options:
minimum: '+1 day'
Mixed absolute and relative dates are also supported:
validators:
-
identifier: DateRange
options:
minimum: '2020-01-01'
maximum: 'today'
The form editor in the TYPO3 backend has been updated to accept these
relative expressions in the date range fields. The HTML
min and
max attributes on the rendered
<input type="date"> element are automatically resolved to
absolute Y- dates at render time.
Impact
Form integrators can now use relative date expressions in the
Date validator configuration. Existing form definitions
using absolute dates will continue to work without changes.