Pro installation quickstart 🚀

Basic example

The repeater input is for repeating groups of inputs. You can use any number of FormKit inputs within a repeater, and repeaters themselves can be infinitely nested.

By default, the repeater input has the ability to shift, add, and remove items:

Load live example

Unlike most other FormKit input types, the repeater input is of type list. You can see above that the users property (our repeater's value) is an array.

Schema example

Like all other FormKit inputs, the Repeater is able to be used in a form written in FormKit schema.

Load live example

Add button attrs

In the previous example, the 'Add Users' button is provided by default, and the button label is derived from the repeater's label. We're able to customize the label by using the add-button prop and setting it to a string, or remove it completely by setting it to false. Alternatively, similar to the submit-attrs prop on the FormKit's forms, we can provide an object of attributes to be applied to the button with add-attrs. In this example, we change the label of the repeater from Add Users to My custom label using the add-label prop:

Load live example

Min/max

Like many other FormKit inputs, the repeater comes with a min and max prop. You can use these props to limit the number of items to be added or removed.

Load live example

Empty state

When a repeater is allowed to be empty by having its min prop set to 0 and having no values, you can control the content rendered in the empty state using the empty slot.

Load live example

Controls

The repeater input by default comes with a set of controls that allow you to shift, add, and remove items. You can control the visibility of these controls by setting the upControl, downControl, insertControl, and removeControl props to true or false.

Load live example

Custom controls

With FormKit's repeater, you are not restricted to our default controls. You can manipulate the repeater in anyway you want:

Load live example

Setting errors

You can set errors on a repeater or any repeatable item using dot notation. Here we are using the setErrors helper, but there are other methods as well:

// the 2nd argument of setErrors is input-level errors
formNode.setErrors( null, // no form errors,
  {
    // error on the repeater field:
    'teamMembers': ['There was a problem with 1 of your team members.']

    // error on a specific repeater item:
    'teamMembers.1.email': ['emily@formkit.com is already on a team.'],
  }
)

Remember, your submit handler is passed the form's core node and can be used to conveniently set errors at depth. Read more about error handling here. Here's an example of a fake backend returning errors for both the repeater and one child:

Load live example

Props & Attributes

PropTypeDefaultDescription
add-labelstringnullUsed to change the label of the add button.
add-attrsobject[object Object]Used to apply attributes to the add button element.
add-buttonbooleantrueConditional for whether to show the add button.
up-controlbooleantrueConditional for whether to show the up control.
down-controlbooleantrueConditional for whether to show the down control.
insert-controlbooleanfalseConditional for whether to show the insert control.
remove-controlbooleantrueConditional for whether to show the remove control.
minNumber1The minimum number of children.
maxNumbernullThe maximum number of children.
Show Universal props
configObject{}Configuration options to provide to the input’s node and any descendent node of this input.
delayNumber20Number of milliseconds to debounce an input’s value before the commit hook is dispatched.
dirtyBehaviorstringtouchedDetermines how the "dirty" flag of this input is set. Can be set to touched or comparetouched (the default) is more performant, but will not detect when the form is once again matching its initial state.
errorsArray[]Array of strings to show as error messages on this field.
helpString''Text for help text associated with the input.
idStringinput_{n}The unique id of the input. Providing an id also allows the input’s node to be globally accessed.
ignoreBooleanfalsePrevents an input from being included in any parent (group, list, form etc). Useful when using inputs for UI instead of actual values.
indexNumberundefinedAllows an input to be inserted at the given index if the parent is a list. If the input’s value is undefined, it inherits the value from that index position. If it has a value it inserts it into the lists’s values at the given index.
labelString''Text for the label element associated with the input.
nameStringinput_{n}The name of the input as identified in the data object. This should be unique within a group of fields.
parentFormKitNodecontextualBy default the parent is a wrapping group, list or form — but this props allows explicit assignment of the parent node.
prefix-iconString''Specifies an icon to put in the prefixIcon section.
preservebooleanfalsePreserves the value of the input on a parent group, list, or form when the input unmounts.
preserve-errorsbooleanfalseBy default errors set on inputs using setErrors are automatically cleared on input, setting this prop to true maintains the error until it is explicitly cleared.
sections-schemaObject{}An object of section keys and schema partial values, where each schema partial is applied to the respective section.
suffix-iconString''Specifies an icon to put in the suffixIcon section.
typeStringtextThe type of input to render from the library.
validationString, Array[]The validation rules to be applied to the input.
validation-visibilityStringblurDetermines when to show an input's failing validation rules. Valid values are blur, dirty, and live.
validation-labelString{label prop}Determines what label to use in validation error messages, by default it uses the label prop if available, otherwise it uses the name prop.
validation-rulesObject{}Additional custom validation rules to make available to the validation prop.
valueAnyundefinedSeeds the initial value of an input and/or its children. Not reactive. Can seed entire groups (forms) and lists..

Sections

You can target a specific section of an input using that section's "key", allowing you to modify that section's classes, HTML (via :sections-schema, or content (via slots)). Read more about sections here.

View on a larger screen to see this section diagram.

Guests
Note guests you will bring to the race track.
Repeated fields here.
🗑
Add guest
Sorry, you may not add more than 3 guests.
Section-keyDescription
fieldsetA fieldset element that acts as the repeater’s wrapper.
legendA legend element that renders the label.
itemsA ul element that wraps the repeater’s items.
itemA li element that is rendered for each repeater item.
contentA container for the group section.
groupDoes not render an element. It structures the default slot into an object data structure.
controlsA ul element that wraps the repeater’s controls.
controlLabelA span element that renders the label of the given control.
upA li element that renders the up control.
upControlA button element that renders the up control.
moveUpIconA span element that renders the upControl’s icon.
downA li element that renders the down control.
downControlA button element that renders the down control.
moveDownIconA span element that renders the downControl’s icon.
insertA li element that renders the insert control.
insertControlA button element that renders the insert control.
insertIconA span element that renders the insertControl’s icon.
removeA li element that renders the remove control.
removeControlA button element that renders the remove control.
removeIconA span element that renders the removeControl’s icon.
Show Universal section keys
outerThe outermost wrapping element.
wrapperA wrapper around the label and input.
labelThe label of the input.
prefixHas no output by default, but allows content directly before an input element.
prefixIconAn element for outputting an icon before the prefix section.
innerA wrapper around the actual input element.
suffixHas no output by default, but allows content directly after an input element.
suffixIconAn element for outputting an icon after the suffix section.
inputThe input element itself.
helpThe element containing help text.
messagesA wrapper around all the messages.
messageThe element (or many elements) containing a message — most often validation and error messages.

Accessibility

All FormKit inputs are designed with the following accessibility considerations in mind. Help us continually improve accessibility for all by filing accessibility issues here:

Semantic markupAria attributesKeyboard accessibleFocus indicatorsColor contrast with the provided themeAccessible labels, help text, and errors
Section KeyAttributeDefaultDescription
itemsrolelistIndicates to assistive technologies that this element functions as a list.
itemrolelistitemIndicates to assistive technologies that this element functions as a list.
Show Universal section key
labellabelforAssociates the label to an input element. Users can click on the label to focus the input or to toggle between states.
inputinputdisabledDisables an HTML element, preventing user interaction and signaling a non-interactive state.
aria-describedbyAssociates an element with a description, aiding screen readers.
aria-requiredAdds this attribute when validation is required.
iconiconforWhenever icon is defined as a label it links it to an input element.

Keyboard Interactions

Keyboard EventDescription
TabMoves the focus to the next focusable input on the page.
Shift + TabMoves the focus to the previous focusable input on the page.