static-cms/website/content/docs/widget-list.mdx

129 lines
3.7 KiB
Plaintext
Raw Normal View History

2022-09-30 11:39:35 -04:00
---
group: Widgets
title: List
weight: 17
2022-09-30 11:39:35 -04:00
---
The list widget allows you to create a repeatable item in the UI which saves as a list of widget values. map a user-provided string with a comma delimiter into a list. You can choose any widget as a child of a list widget—even other lists.
* **Name:** `list`
* **UI:** without any `fields` specified, the list widget defaults to a text input for entering comma-separated values; with `fields` specified, the list widget contains a repeatable child widget, with controls for adding, deleting, and re-ordering the repeated widgets.
* **Data type:** list of widget values
* **Options:**
* `default`: you may specify a list of strings to populate the basic text
field, or an array of list items for lists using the `fields` option. If no
default is declared when using `field` or `fields`, will default to a single
list item using the defaults on the child widgets
* `allow_add`: `false` hides the button to add additional items
* `collapsed`: when `true`, the entries collapse by default
* `summary`: specify the label displayed on collapsed entries
* `minimize_collapsed`: when `true`, collapsing the list widget will hide all of it's entries instead of showing summaries
* `label_singular`: the text to show on the add button
* `field`: a single widget field to be repeated
* `fields`: a nested list of multiple widget fields to be included in each repeatable iteration
* `max`: maximum number of items in the list
* `min`: minimum number of items in the list
* `add_to_top`: when `true`, new entries will be added to the top of the list
* **Example** (`field`/`fields` not specified):
```yaml
- label: "Tags"
title: "tags"
2022-09-30 11:39:35 -04:00
widget: "list"
default: ["news"]
```
* **Example** (`allow_add` marked `false`):
```yaml
- label: "Tags"
title: "tags"
2022-09-30 11:39:35 -04:00
widget: "list"
allow_add: false
default: ["news"]
```
* **Example** (with `field`):
```yaml
- label: "Gallery"
title: "galleryImages"
2022-09-30 11:39:35 -04:00
widget: "list"
summary: '{{fields.image}}'
field: {label: Image, title: image, widget: image}
2022-09-30 11:39:35 -04:00
```
* **Example** (with `fields`):
```yaml
- label: "Testimonials"
title: "testimonials"
2022-09-30 11:39:35 -04:00
widget: "list"
summary: '{{fields.quote}} - {{fields.author.name}}'
fields:
- {label: Quote, title: quote, widget: string, default: "Everything is awesome!"}
2022-09-30 11:39:35 -04:00
- label: Author
title: author
2022-09-30 11:39:35 -04:00
widget: object
fields:
- {label: Name, title: name, widget: string, default: "Emmet"}
- {label: Avatar, title: avatar, widget: image, default: "/img/emmet.jpg"}
2022-09-30 11:39:35 -04:00
```
* **Example** (with `default`):
```yaml
- label: "Gallery"
title: "galleryImages"
2022-09-30 11:39:35 -04:00
widget: "list"
fields:
- { label: "Source", title: "src", widget: "string" }
- { label: "Alt Text", title: "alt", widget: "string" }
2022-09-30 11:39:35 -04:00
default:
- { src: "/img/tennis.jpg", alt: "Tennis" }
- { src: "/img/footbar.jpg", alt: "Football" }
```
* **Example** (`collapsed` marked `false`):
```yaml
- label: "Testimonials"
title: "testimonials"
2022-09-30 11:39:35 -04:00
collapsed: false
widget: "list"
fields:
- {label: Quote, title: quote, widget: string, default: "Everything is awesome!"}
- {label: Author, title: author, widget: string }
2022-09-30 11:39:35 -04:00
```
* **Example** (`minimize_collapsed` marked `true`):
```yaml
- label: "Testimonials"
title: "testimonials"
2022-09-30 11:39:35 -04:00
minimize_collapsed: true
widget: "list"
fields:
- {label: Quote, title: quote, widget: string, default: "Everything is awesome!"}
- {label: Author, title: author, widget: string }
2022-09-30 11:39:35 -04:00
```
* **Example** (with `max` & `min`):
```yaml
- label: "Tags"
title: "tags"
2022-09-30 11:39:35 -04:00
widget: "list"
max: 3
min: 1
default: ["news"]
```
* **Example** (`add_to_top` marked `true`):
```yaml
- label: "Tags"
title: "tags"
2022-09-30 11:39:35 -04:00
widget: "list"
add_to_top: true
```