Skip to content

Hidden Field

The Hidden field type is used to store values that should not be visible or editable by users in the entry form. It is typically used for metadata or system-generated values.

User Interface

None. A hidden field does not render any UI components in the entry form.

Data Type

Any value assigned programmatically or via default settings.

Data Validation

No specific data validation is applied to the Hidden field, as its value is not user-editable.

Options

In addition to the common field options, the Hidden field supports the following options:

Required Options

widget

  • Type: string
  • Default: string

Must be set to hidden.

default

  • Type: any
  • Default: ""

The default value for the hidden field when creating a new entry. Any data type is accepted (string, number, boolean, object, array, etc.) as long as it can be serialized to the collection’s data format (YAML, JSON, TOML, etc).

TOML does not support null values, so avoid using null as the default value when the collection’s data format is set to TOML.

The default value supports the following template tags:

  • {{locale}}: The current locale code when i18n support is enabled, e.g. en or fr.
  • {{datetime}}: The current date/time in ISO 8601 format.
  • {{uuid}}, {{uuid_short}} and {{uuid_shorter}}: A random UUID or its shorter version, just like the slug template tags.
  • {{author-email}}, {{author-login}} and {{author-name}}: The signed-in user’s email, login name and display name, respectively, just like commit message tags. These tags don’t work with the Local Workflow because the user is not authenticated via a Git backend.

Examples

Embedding UUID in a Hidden Field

This example shows how to create a hidden field that automatically generates and stores a UUID for each entry. This can be useful for uniquely identifying entries.

yaml
- name: unique_id
  label: Unique ID
  widget: hidden
  default: '{{uuid}}'
toml
[[fields]]
name = "unique_id"
label = "Unique ID"
widget = "hidden"
default = "{{uuid}}"
json
{
  "name": "unique_id",
  "label": "Unique ID",
  "widget": "hidden",
  "default": "{{uuid}}"
}
js
{
  name: 'unique_id',
  label: 'Unique ID',
  widget: 'hidden',
  default: '{{uuid}}',
}

Embedding the Author’s Name in a Hidden Field

This example shows how to create a hidden field that automatically captures the name of the user creating the entry.

yaml
- name: author_name
  label: Author Name
  widget: hidden
  default: '{{author-name}}'
toml
[[fields]]
name = "author_name"
label = "Author Name"
widget = "hidden"
default = "{{author-name}}"
json
{
  "name": "author_name",
  "label": "Author Name",
  "widget": "hidden",
  "default": "{{author-name}}"
}
js
{
  name: 'author_name',
  label: 'Author Name',
  widget: 'hidden',
  default: '{{author-name}}',
}

Released under the MIT License.