Skip to content

Repeater

Repeater components are Input 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.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
uid: 'repeater_basic',
kind: 'input',
type: 'repeater',
path: 'guests',
label: 'Guest List',
props: {
addLabel: 'Add Guest',
removeLabel: 'Remove Guest',
template: {
kind: 'layout',
type: 'flex',
children: [
{
kind: 'input',
type: 'textinput',
path: 'guests.items.guest_name',
label: 'Full Name',
},
],
},
},
},
],
});

Use this props to customize your Repeater component.

proptypevalue
templateobjectMANDATORY A template Field with the elements rendered by the repeater
addLabelstringLabel text for the add button
removeLabelstringLabel text for the remove button
limitnumberMaximum number of items that can be added
titlestringOptional title displayed at the top of each card
addButtonIconstringCSS class string for the icon displayed in the add button
removeButtonIconstringCSS class string for the icon displayed in the remove button

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 Input 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.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
uid: 'repeater_basic',
kind: 'input',
type: 'repeater',
path: 'guests',
label: 'Guest List',
props: {
addLabel: 'Add Guest',
removeLabel: 'Remove Guest',
template: {
kind: 'layout',
type: 'flex',
children: [
{
kind: 'input',
type: 'textinput',
path: 'guests.items.guest_name',
label: 'Full Name',
},
],
},
},
},
],
});

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

repeater.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'repeater',
path: 'users',
defaultValue: [
{
firstName: 'John',
lastName: 'Doe',
},
{
firstName: 'Jane',
lastName: 'Doe',
},
],
props: {
addLabel: 'Add new developer',
removeLabel: 'Remove developer',
template: {
kind: 'layout',
type: 'flex',
children: [
{
kind: 'input',
type: 'textinput',
path: 'users.items.firstName',
},
{
kind: 'input',
type: '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.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
uid: 'repeater_limit',
kind: 'input',
type: 'repeater',
path: 'contacts',
label: 'Emergency Contacts',
props: {
limit: 3,
addLabel: 'Add Contact',
removeLabel: 'Delete',
template: {
kind: 'layout',
type: 'flex',
children: [
{
kind: 'input',
type: 'textinput',
path: 'contacts.items.phone',
label: 'Phone Number',
},
],
},
},
},
],
});

Use the property title to display a static title at the top of each card.

repeater.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
uid: 'repeater_title',
kind: 'input',
type: 'repeater',
path: 'guests',
label: 'Guest List',
props: {
title: 'Guest',
addLabel: 'Add Guest',
removeLabel: 'Remove',
template: {
kind: 'layout',
type: 'flex',
children: [
{
kind: 'input',
type: 'textinput',
path: 'guests.items.guest_name',
label: 'Full Name',
},
],
},
},
},
],
});

Use the properties addButtonIcon and removeButtonIcon to display an icon inside the add and remove buttons. Icons are passed as a CSS class string, the same way as other icon props in the library.

repeater.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
uid: 'repeater_icons',
kind: 'input',
type: 'repeater',
path: 'guests',
label: 'Guest List',
props: {
addLabel: 'Add Guest',
removeLabel: 'Remove',
addButtonIcon: 'add',
removeButtonIcon: 'remove',
template: {
kind: 'layout',
type: 'flex',
children: [
{
kind: 'input',
type: 'textinput',
path: 'guests.items.guest_name',
label: 'Full Name',
},
],
},
},
},
],
});

Repeaters can be nested inside other repeaters to model hierarchical data structures. Each nesting level adds an additional .items. segment to the path. For example, in a Teams → Members structure:

  • The outer repeater path is teams
  • Fields inside the outer template use teams.items.fieldName
  • The inner repeater path is teams.items.members
  • Fields inside the inner template use teams.items.members.items.fieldName

At runtime, each items token is replaced by the corresponding array index. For instance, teams.items.members.items.memberName becomes teams[0].members[1].memberName for the second member of the first team.

repeater.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
uid: 'team_repeater',
kind: 'input',
type: 'repeater',
path: 'teams',
label: 'Teams',
props: {
addLabel: 'Add Team',
removeLabel: 'Remove Team',
template: {
kind: 'layout',
type: 'flex',
props: {
direction: 'column',
},
children: [
{
kind: 'input',
type: 'textinput',
path: 'teams.items.teamName',
label: 'Team Name',
},
{
uid: 'member_repeater',
kind: 'input',
type: 'repeater',
path: 'teams.items.members',
label: 'Members',
props: {
addLabel: 'Add Member',
removeLabel: 'Remove Member',
template: {
kind: 'layout',
type: 'flex',
children: [
{
kind: 'input',
type: 'textinput',
path: 'teams.items.members.items.memberName',
label: 'Member Name',
},
],
},
},
},
],
},
},
},
],
});

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
<div class="gui-repeater">
<div id="repeater_uid">
<h2>Guest List</h2>
<div class="gui-repeater__card">
<div class="gui-repeater__card-header">
<span class="gui-repeater__card-title">Guest</span>
<button type="button" class="gui-button gui-repeater__remove-btn">
<span class="gui-button-icon delete"></span>
Remove Guest
</button>
</div>
<gui-repeater-widget>
<div class="gui-label">
<label>Full Name</label>
</div>
<div class="gui-widget">
<input type="text" value="John Doe" />
</div>
</gui-repeater-widget>
</div>
<button type="button" class="gui-button gui-repeater__add-btn">
<span class="gui-button-icon person_add"></span>
Add Guest
</button>
</div>
</div>