Widgets define the data type and interface for entry fields. Static CMS comes with several built-in widgets. Click the widget names in the sidebar to jump to specific widget details. You can also create your own!
Widgets are specified as collection fields in the Static CMS config
file. Note that YAML syntax allows lists and objects to be written in block or inline style, and the code samples below include a mix of both.
To see working examples of all of the built-in widgets, try making a ‘Kitchen Sink’ collection item on the CMS demo site. (No login required: click the login button and Static CMS will open.) You can refer to the demo configuration code to see how each field was configured.
Available Widgets
Name 17386_2f6772-9a> |
Description 17386_570916-47> |
---|---|
Boolean 17386_8faf49-ba> |
The boolean widget translates a toggle switch input to a true or false value 17386_dc789f-c4> |
Code 17386_6f7074-a4> |
The code widget provides a code editor (powered by Codemirror) with optional syntax awareness 17386_18a675-a5> |
Color 17386_6ed533-98> |
The color widget translates a color picker to a color string 17386_b3c9cc-93> |
Datetime 17386_a94244-5d> |
The datetime widget translates a datetime picker to a datetime string 17386_3841c8-18> |
File 17386_670eca-d2> |
The file widget allows editors to upload a file or select an existing one from the media library 17386_eca8cc-1a> |
Hidden 17386_1deab2-eb> |
Hidden widgets do not display in the UI 17386_f00dac-c0> |
Image 17386_4ab595-06> |
The file widget allows editors to upload a file or select an existing one from the media library 17386_ad8e72-99> |
Key Value 17386_99a99c-f1> |
The key value widget allows editors to enter an arbitrary number of key/value pairs. 17386_58a600-26> |
List 17386_f37a1d-01> |
The list widget allows you to create a repeatable item in the UI which saves as a list of widget values 17386_e1f60a-99> |
Map 17386_fb66f8-0b> |
The map widget allows you to edit spatial data using an interactive map 17386_70299d-f0> |
Markdown 17386_fb322e-2e> |
The markdown widget provides a full fledged text editor allowing users to format text with features such as headings and blockquotes 17386_210fa4-4a> |
17386_1505de-d1> |
The number widget uses an HTML number input 17386_ce5c99-6b> |
Object 17386_f1cdda-0c> |
The object widget allows you to group multiple widgets together, nested under a single field 17386_1d8d70-51> |
Relation 17386_bd25cb-f6> |
The relation widget allows you to reference items from another collection 17386_38ebe9-82> |
Select 17386_c1cf59-bf> |
The select widget allows you to pick a string value from a dropdown menu 17386_513ee2-2a> |
String 17386_25c4bf-5a> |
The string widget translates a basic text input to a string value 17386_863389-0e> |
Text 17386_04bdd7-fe> |
The text widget takes a multiline text field and saves it as a string 17386_22cdb3-ac> |
UUID 17386_58e26b-fd> |
The uuid widget generates a unique id (uuid) and saves it as a string 17386_2d662a-6e> |
Common widget options
The following options are available on all fields:
Name 17386_c9ab1e-93> |
Type 17386_44ad05-88> |
Default 17386_8a031a-fb> |
Description 17386_6401d4-00> |
---|---|---|---|
name 17386_8569bb-63> |
string 17386_8837fd-39> | 17386_05eb06-8f> |
The name of the field 17386_e23c73-fa> |
widget 17386_e03c80-39> |
string 17386_93c0f1-96> |
|
Optional. The type of widget to render for the field 17386_928939-0a> |
label 17386_df360e-cc> |
string 17386_8da4a4-79> |
|
Optional. The display name of the field 17386_05b50b-c2> |
required 17386_ce07b6-8f> |
boolean 17386_b808e8-8b> |
|
Optional. Specify as |
hint 17386_0d17fa-1f> |
string 17386_ae12a3-7c> | 17386_5658d8-75> |
Optional. Adds helper text directly below a widget. Useful for including instructions. Accepts markdown for bold, italic, strikethrough, and links. 17386_3a7b73-f4> |
pattern 17386_12da54-11> |
list of strings 17386_8009f4-02> | 17386_067efb-d1> |
Optional. Adds field validation by specifying a list with a regex pattern and an error message; more extensive validation can be achieved with custom widgets 17386_d322ef-e6> |
i18n 17386_5743fa-24> |
boolean | 17386_8dd3ec-1d> |
Optional. |
condition 17386_a9da02-98> |
FilterRule | 17386_6f6319-fa> |
Optional. See Field Conditions 17386_a91aad-d7> |
Example Widget
name: title
label: Title
widget: string
pattern: ['.{12,}', 'Must have at least 12 characters']
name: 'title',
label: 'Title',
widget: 'string',
pattern: ['.{12,}', 'Must have at least 12 characters'],
Field Conditions
The fields can be shown conditionally based on the values of the other fields.
The condition
option can take a single filter rule or a list of filter rules.
Name 17386_29e19d-f0> |
Type 17386_a0f2e9-d0> |
Default 17386_b5311b-b6> |
Description 17386_92efc2-ee> |
---|---|---|---|
field 17386_aead95-e1> |
string 17386_d0a0be-20> | 17386_a4dc3a-0b> |
The name of one of the field. 17386_05bcb7-50> |
value 17386_7fa782-e6> |
string | 17386_11cff6-3f> |
Optional. The desired value or values to match. Required if no |
pattern 17386_dd8d24-3a> |
regular expression 17386_f33619-53> | 17386_7ab3bc-99> |
Optional. A regex pattern to match against the field’s value 17386_ffae4e-6e> |
matchAll 17386_7d3bc8-11> |
boolean 17386_8c9240-f2> |
|
Optional. Ignored if value is not a list of strings |
Example
The example below conditionally shows fields based on the values of other fields.
collections:
- name: 'nested-field-filtered-collection'
label: 'Nested Field Filtered Collection'
folder: '_field_condition'
create: true
fields:
- name: type
label: Type
widget: select
options:
- value: type1
label: Type 1
- value: type2
label: Type 2
- name: value1
label: Value 1
widget: string
condition:
field: type
value: type1
- name: value2
label: Value 2
widget: text
condition:
field: type
value: type2
collections: [
{
name: "nested-field-filtered-collection",
label: "Nested Field Filtered Collection",
folder: "_field_condition",
create: true,
fields: [
{
name: "type",
label: "Type",
widget: "select",
options: [
{
value: "type1",
label: "Type 1"
},
{
value: "type2",
label: "Type 2"
}
]
},
{
name: "value1",
label: "Value 1",
widget: "string",
condition: {
field: "type",
value: "type1"
}
},
{
name: "value2",
label: "Value 2",
widget: "text",
condition: {
field: "type",
value: "type2"
}
}
]
}
],
Nested Field Example
The example below conditionally shows fields based on the values of other nested fields.
collections:
- name: 'nested-field-filtered-collection'
label: 'Nested Field Filtered Collection'
folder: '_nested_field_condition'
create: true
fields:
- name: value
label: Value 1
widget: string
condition:
field: nested.object.field
value: yes
- name: nested
label: Nested
widget: object
fields:
- name: object
label: Object
widget: object
fields:
- name: field
label: Field
widget: select
options:
- yes
- no
collections: [
{
name: "nested-field-filtered-collection",
label: "Nested Field Filtered Collection",
folder: "_nested_field_condition",
create: true,
fields: [
{
name: "value",
label: "Value 1",
widget: "string",
condition: {
field: "nested.object.field",
value: "yes"
}
},
{
name: "nested",
label: "Nested",
widget: "object",
fields: [
{
name: "object",
label: "Object",
widget: "object",
fields: [
{
name: "field",
label: "Field",
widget: "select",
options: [
"yes",
"no"
]
}
]
}
]
}
]
}
],
List Field Example
The example below conditionally shows fields inside a list based on the values of other fields in the same list item. This works with both fields
or types
.
collections:
- name: list-field-filtered-collection
label: List Field Filtered Collection
folder: _list_field_condition
create: true
fields:
- name: list
label: List Field
widget: list
fields:
- name: value
label: Value 1
widget: string
condition:
field: nested.object.field
value: yes
- name: nested
label: Nested
widget: object
fields:
- name: object
label: Object
widget: object
fields:
- name: field
label: Field
widget: select
options:
- yes
- no
collections: [
{
name: "list-field-filtered-collection",
label: "List Field Filtered Collection",
folder: "_list_field_condition",
create: true,
fields: [
{
name: "list",
label: "List Field",
widget: "list",
fields: [
{
name: "value",
label: "Value 1",
widget: "string",
condition: {
field: "nested.object.field",
value: "yes"
}
},
{
name: "nested",
label: "Nested",
widget: "object",
fields: [
{
name: "object",
label: "Object",
widget: "object",
fields: [
{
name: "field",
label: "Field",
widget: "select",
options: [
"yes",
"no"
]
}
]
}
]
}
]
}
]
}
],