Repeater¶
The base for any list of rows or cards of mixed fields. Each item is a row of fields, or a boxed card with a title and its fields in a grid. Rows add and remove, keep a least and a most, and move up and down. It is built on the row editor core, which the Access Schedule shares, and its rows sit in a List. The Key Value Editor and the Rule Builder are built on it. Every field checks through the validation core, so a Save Bar with form, or validateAll, covers it.
Decision¶
| When | Use |
|---|---|
| A list of records the reader adds, edits, and removes in place, such as servers, webhooks, or schedules | Repeater |
| A record with more fields than fit on one row | layout: 'card' |
| Two text fields | Key Value Editor |
| One text field | String List |
| Records that are mostly read and edited one at a time | A Data Table with editable |
Usage¶
import { createRepeater } from './configurationpage?name=myplugin_stolon.js';
var servers = createRepeater({
fields: [
{ key: 'name', label: 'Name', required: true },
{ key: 'url', label: 'Address', placeholder: 'https://jellyfin.example.com', width: '2fr' },
{ key: 'token', label: 'Token', type: 'secret', allowExpose: true },
{ key: 'kind', label: 'Kind', type: 'select', options: [{ value: 'main', label: 'Main' }, { value: 'backup', label: 'Backup' }] },
{ key: 'on', label: 'Enabled', type: 'toggle' }
],
value: config.Servers,
reorder: true,
addText: 'Add Server',
onChange: function (value) { config.Servers = value; bar.setDirty(true); }
});
view.querySelector('#serversHost').appendChild(servers.element);
The handle is { element, getValue, setValue, setItems, addRow, isValid, setHeight, destroy }.
States and Modifiers¶
- A field is
{ key, label, type, options, placeholder, required, requiredText, min, max, step, allowExpose, width, hidden, visible, labelFor, clearable, clearText, transform, validate, render }. - An item's keys that no field shows ride along with its row, and so does a
hidden: truefield, which draws nothing.getValue()gives them back, so an id or a name a row was saved under is never lost. A row is blank, and left out, when every field it shows is empty. visible(item)shows a field only in the rows it returns true for. An inline row keeps the field's place, and a hidden field never stops a save.labelFor(item)gives a label that follows the row, falling back tolabel.newItem()returns the values a new row starts with, for Add andaddRow().clearable: trueon a secret adds a Clear button after its box while a secret is stored, "Clear {value}" byclearText. Clear empties it, and the row then posts''for it.transform(text)rewrites a text or secret field as it is typed, such as to upper case, keeping the caret.typepicks the control.textis a text box,secreta secret field with its three states and the eye withallowExpose,selectthe form select ofoptions,numbera number box with Stolon's arrows,tagsthe Tag Input,timea time box with its picker icon,togglean on and off control a field tall, andcustomthe controlrender(value, change)returns as{ element, input, getValue, setValue, destroy }.- A secret's value is the kept sentinel,
SECRET_KEPT, while a secret is stored but not on the page, andgetValue()gives it back for a field left untouched. required,min,max, andvalidate(value, item, index)check through the validation core, with the field's label as the noun, such as "Enter a name.". A message shows under its field once the reader leaves it, then follows each change.isValid()checks every field, shows every message, and moves focus to the first invalid one.layout: 'inline'(default) draws a row per item on shared column tracks under the field labels, and marks the rootstolon-repeater-layout-inline.widthsets a field's track, a share by default.showLabels: falsehides the labels.layout: 'card'marks the rootstolon-repeater-layout-cardand draws each item as a card whose title istitleText, "Item {index}" by default, where{index}is its number and{key}any field's value. Its row buttons sit at the top right.reorder: trueadds up and down buttons to each row, and focus stays on the pressed one.height,maxHeight, andminHeightsize the rows as a List takes them,'auto'by default, andsetHeightchanges them.sizeis'small','medium'(default), or'large'for every field.minRowsdisables Remove at that count and fills empty rows up to it.maxRowsdisables Add and showslimitText.removeTextis "Remove {value}", where the value is the row's name: its first text field, else "Row 2" fromrowName, or a card's title.upTextanddownTextare "Move {value} up" and "Move {value} down".emptyTextshows under the rows while there is none.- An inline repeater too narrow for its fields side by side turns
compact: the column labels hide, and each row stacks its fields full width under their own labels, with the row buttons at the top right.
Gotchas¶
getValue()leaves out a row whose fields are all empty. A select with noplaceholderalways holds one of its choices, so its row is never empty.setValuedoes not callonChange.- The layout classes carry the
stolon-repeater-layout-prefix because Jellyfin styles a barecardclass with paint containment, which would trap a dropdown inside the repeater. A page style that targets a layout uses.stolon-repeater-layout-cardor.stolon-repeater-layout-inline.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
createRepeater¶
function createRepeater(options: RepeaterOptions): RepeaterHandle
The base for any list of rows or cards of mixed fields, built on the row editor core. Each item is a row of fields, or a card with a title and its fields in a grid. Rows add and remove, keep minRows and maxRows, and move up and down with reorder. Every field validates through the field core, with its message under it.
| Option | Type | What it does |
|---|---|---|
fields (required) |
RepeaterField[] |
array of { key, label, type ('text', 'secret', 'select', 'number', 'tags', 'time', 'toggle', or 'custom'), options, placeholder, required, requiredText, min, max, step, allowExpose, width, hidden (true carries the value with no control), visible(item), labelFor(item), clearable (a Clear button on a stored secret), clearText (default 'Clear {value}'), transform(text), validate(value, item, index), render(value, change) } [required] |
layout |
'inline' | 'card' |
'inline' for one row of fields per item, or 'card' for a boxed card per item (default 'inline') |
value |
RepeaterItem[] | null |
array of items, each an object of values by field key [optional] |
addText |
string |
text of the add button (default 'Add') |
removeText |
string |
aria-label of a remove button, where {value} is the row's name (default 'Remove {value}') |
upText |
string |
|
downText |
string |
|
rowName |
string |
prefix of the name of an inline row whose first text field is empty (default 'Row') |
titleText |
string |
a card's title, where {index} is its number and {key} any field's value, or the label of its chosen option for a field with options (default 'Item {index}') |
showLabels |
boolean |
false hides the column labels over inline rows (default true) |
maxRows |
number |
most rows allowed, after which Add is disabled and limitText shows [optional] |
minRows |
number |
fewest rows, below which Remove is disabled, and up to which empty rows are added [optional] |
limitText |
string |
message when maxRows is reached (default 'No more rows can be added.') |
reorder |
boolean |
true adds up and down buttons to each row (default false) |
emptyText |
string |
sentence shown while there is no row [optional] |
height |
ListHeight |
|
maxHeight |
number | string | null |
|
minHeight |
number | string | null |
|
size |
'small' | 'medium' | 'large' |
'small', 'medium', or 'large' for its fields (default 'medium') |
newItem |
(): RepeaterItem | null | undefined |
function() returning the values a new row starts with, for Add and addRow() [optional] |
onChange |
(value: RepeaterItem[]): void |
function(value) after each change [optional] |
| Handle member | Type |
|---|---|
getValue |
(): RepeaterItem[] |
setValue |
(next: RepeaterItem[] | null): void |
setItems |
(next: RepeaterItem[] | null): void |
addRow |
(item?: RepeaterItem | null): boolean |
isValid |
(): boolean |
setHeight |
(height: ListHeight, maxHeight?: number | string | null): void |
destroy |
(): void |
| Type | What it is |
|---|---|
RepeaterField |
One field of a repeater row. type picks the control: a text box, a secret with its three states and allowExpose, the form select with options, a number with min, max, and step, the tag input, a time box, a toggle, or a custom control from render(value, change). validate(value, item, index) returns an error sentence, or an empty value when the value is valid. width is the field's grid track in the inline layout, such as '2fr' or '8rem'. hidden carries a value with no control, visible(item) shows the field only in the rows it returns true for, labelFor(item) gives a label that follows the row, clearable adds a Clear button to a stored secret, and transform(text) rewrites text as it is typed. |
RepeaterFieldType |
The kinds of control a repeater field can be. |
RepeaterChoice |
One choice of a select field, as { value, label } or as plain text. |
RepeaterControl |
What a custom field's render returns: its element, the input its label names, and how to read and set its value. |
RepeaterItem |
One row of a repeater, as an object of field values by key. |
RepeaterParts |
The classes and behavior a variation built on the repeater sets, such as the Key Value Editor's own class names. Internal to the web components. |
RepeaterRow |
One drawn row of a repeater, with its field group. Internal to the web components. |
RepeaterBuild |
What buildRepeater returns: the handle, the rows, and a check that may leave focus alone. Internal to the web components. |
| Class | What it looks like |
|---|---|
stolon-repeater |
A list of rows or cards of mixed fields, with an Add button under them |
stolon-repeater-head |
Column labels over inline rows, on the rows' own tracks with room for the row buttons |
stolon-repeater-rows |
The rows, a gap apart |
stolon-repeater.stolon-repeater-layout-inline |
One inline row: a cell per field on the shared tracks, then the row buttons |
stolon-field-cell |
A field's cell: its label, its control, and its message under it |
stolon-control-toggle |
A toggle field: the shared Checkbox a field tall, its box centered on the line of the fields beside it |
stolon-control-secret.stolon-clearable |
A secret with a Clear button after its box, shown while a secret is stored |
stolon-repeater-actions |
The row buttons, the moves and the remove, at the row's end and centered on its first field |
stolon-repeater.stolon-repeater-layout-card |
One card: a head with the title and the row buttons at the top right, over its fields in a grid |
stolon-field-group.stolon-grid |
Fields in as many columns as fit, each under its label |
stolon-repeater.stolon-repeater-layout-inline.stolon-compact |
A narrow inline repeater: each row stacks its fields full width under their labels, with the row buttons pinned top right, level with the first label |
Example¶
Example Code¶
<!-- title: Repeater -->
<div style="display: grid; gap: 24px;">
<div id="inline"></div>
<div id="cards"></div>
</div>
<script type="module">
const base = await window.__baseReady;
const inline = base.createRepeater({
fields: [
{ key: 'name', label: 'Name', required: true, placeholder: 'Living Room' },
{ key: 'port', label: 'Port', type: 'number', min: 1, max: 65535, placeholder: '8096' },
{ key: 'kind', label: 'Kind', type: 'select', options: [{ value: 'main', label: 'Main' }, { value: 'backup', label: 'Backup' }] },
{ key: 'on', label: 'Enabled', type: 'toggle' }
],
value: [{ name: 'Living Room', port: 8096, kind: 'main', on: true }, { name: 'Office', port: 8920, kind: 'backup', on: false }],
reorder: true,
minRows: 1,
maxRows: 5,
addText: 'Add Server'
});
document.getElementById('inline').appendChild(inline.element);
const cards = base.createRepeater({
layout: 'card',
titleText: 'Webhook {index}',
fields: [
{ key: 'url', label: 'Address', required: true, placeholder: 'https://hooks.example.com/sync' },
{ key: 'token', label: 'Token', type: 'secret', allowExpose: true },
{ key: 'events', label: 'Events', type: 'tags', placeholder: 'sync.done' },
{ key: 'at', label: 'Quiet From', type: 'time' }
],
value: [{ url: 'https://hooks.example.com/sync', token: base.SECRET_KEPT, events: ['sync.done', 'sync.failed'], at: '22:00' }],
addText: 'Add Webhook',
emptyText: 'No webhooks yet.'
});
document.getElementById('cards').appendChild(cards.element);
</script>