Skip to content

Repeater

Repeater components are Control Fields that allow the user to enter information as a list given a template. The information will be stored and returned as an array of objects.

repeater.json
{
"form": {
"uid": "",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "repeater",
"path": "users",
"defaultValue": [
{
"firstName": "John",
"lastName": "Doe"
},
{
"firstName": "Jane",
"lastName": "Doe"
}
],
"props": {
"template": {
"uid": "",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "users.items.firstName"
},
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "users.items.lastName"
}
]
}
}
}
]
}
}

Use this props to customize your Repeater component.

proptypevalue
templateobjectMANDATORY A template Field with the elements rendered by the repeater
addLabelstringA placeholder text to display when the text input has no value
removeLabelstringA description to display below the text input
limitnumberA css class to display an icon

Use the property template to render a tree of Field components for each item in the array of the Repeater component. The path in the Control Fields components inside the template will be updated replacing items keyword by the index of the array. For example, users.items.firstName will be replaced by users[0].firstName for the first element and so on.

repeater.json
{
"form": {
"uid": "",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "repeater",
"path": "users",
"defaultValue": [
{
"firstName": "John",
"lastName": "Doe"
},
{
"firstName": "Jane",
"lastName": "Doe"
}
],
"props": {
"template": {
"uid": "",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "users.items.firstName"
},
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "users.items.lastName"
}
]
}
}
}
]
}
}

Use the property addLabel and removeLabel to set custom labels for the Add and Remove button.

repeater.json
{
"form": {
"uid": "",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "repeater",
"path": "users",
"defaultValue": [
{
"firstName": "John",
"lastName": "Doe"
},
{
"firstName": "Jane",
"lastName": "Doe"
}
],
"props": {
"addLabel": "Add new developer",
"removeLabel": "Remove developer",
"template": {
"uid": "",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "users.items.firstName"
},
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "users.items.lastName"
}
]
}
}
}
]
}
}

Use the property limit to set a limit to the number of elements that can be added to a repeater.

repeater.json
{
"form": {
"uid": "",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "repeater",
"path": "users",
"defaultValue": [
{
"firstName": "John",
"lastName": "Doe"
},
{
"firstName": "Jane",
"lastName": "Doe"
}
],
"props": {
"limit": 2,
"template": {
"uid": "",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "users.items.firstName"
},
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "users.items.lastName"
}
]
}
}
}
]
}
}

Repeaters can be styled as explained in the Styling Guide.

Following you will find a list with the CSS Variables and a quick description of what you will style.

CSS VariableDescription
--gui-space-gapSpace between each repeater element
--gui-field-gapSpace between Add/Remove buttons
--gui-paddingRepeater element padding
--gui-color-borderRepeater element border color
--gui-radiusRepeater element border radius
--gui-color-bgRepeater element background color
--gui-color-fgRepeater element text color

This is the anatomy of the Repeater Component in case you want to use your CSS styles.

repeater.html
<gui-repeater>
<div id="fieldUid">
<h2>Label</h2>
<div class="card">
<gui-stack class="gui-stack">
<!-- CONTENT -->
</gui-stack>
<button type="button" class="gui-button" disabled>Remove</button>
</div>
<button type="button" class="gui-button" disabled>ADD</button>
</div>
</gui-repeater>