HTML5 allows you to set default values (using the value attribute) and also to specify minimum and maximum acceptable values on numeric and date fields (using the min and max attributes).
With date, datetime and time values you may want these values to be relative - for example relative to "today".
As an example you may want a field for a Date of BIrth to only allow dates which make the age of the person 18 or over (i.e. an adult) and less than 120 years (i.e. possibly still alive). Using just HTML5 this cannot be achieved as the min and max attributes only accept absolute values (i.e. an actual date, time or datetime value).
formstrap allows you to specify a formula for the default value and min/max attributes that are evaluated whenever the live form is loaded.
Field Settings
When editing the field settings of a date, date-time or time field you will notice a formula icon in the label of the default value and min / max fields:
Click the function icon and a form will pop up: In this example, we have specified that the min value must be greater than the current date minus 120 years.
Before the formula can be saved it must be tested. Click the test button and the formula will be evaluated.This screenshot was produced on 28th April 2025.
If you are happy with the way the formula works, click save and the metadata form will be updated: You can edit the formula by clicking the button or revert to an absolute value by clicking the calendar icon.
You can then repeat the process above for the max attribute with a date that is today minus 18 years.
Custom Formula
If you want to specify a more complex formula you can use the Custom Formula option.
With the custom formula you simply enter the formula in simple natural language terms.
For example:
Desired Result | Enter this String |
---|---|
Next Saturday (i.e. the first Saturday after today) | Next Saturday |
The last day of the current month | Last day of this Month |
16 days from today | +16 days |
You will be informed if the custom "formula" you have entered could not be evaluated and should try to reformulate.
If the formula is successful, please check the date returned matches your expectation before saving the formula as the script may misunderstand your natural language query.
The custom formula uses the Javascript equivalent of the PHP strtotime() function by Locutus.