Skip to main content

Repeater

A repeater field allows users to create a set of fields that can be duplicated multiple times within a form. It is especially useful for scenarios where multiple entries of similar data are needed, such as product variations or multiple contact details. The repeater field also supports a drag-and-drop interface for sorting the repeated entries, providing a flexible and intuitive way to manage the data.

Screenshots

Field render in form:

field preview

Field render in field group:

field preview

Configuration

  • Settings:

    • Name: The label for the field.
    • Slug: The unique technical identifier.
    • Fields: The individual fields that are included within each repetition of the repeater.
  • Validation:

    • Require: Determines if at least one set of fields must be filled out.
    • Number min of elements: Minimum number of repetitions required.
    • Number max of elements: Maximum number of repetitions allowed.`
  • Design:

    • Instructions: Text displayed alongside the field providing details about the data needed.
    • Width: The width of the field in the form.
    • Classes: Custom CSS classes for styling the field.
    • ID: Custom ID attribute for the field.
    • Text before: Additional text displayed before the field.
    • Text after: Additional text displayed after the field.

Return format

  • Type: array
  • Value:
[
[
'sub_field_slug_one' => 'First element value',
'sub_field_slug_two' => 'First element value',
],
[
'sub_field_slug_one' => 'Second element value',
'sub_field_slug_two' => 'Second element value',
],
]

Usage

/some-template.tpl
{* Object or Entity and Id *}
{assign var="data" value=$modules.customfieldgroups.data->get($product)}
{assign var="data" value=$modules.customfieldgroups.data->get('product', $product.id)}

{foreach from=$data.field_group_slug.field_slug item=row}
<div>
<span>{$row.field_slug_txt}</span>

{if $row.field_slug_img}
<img src="{$row.field_slug_img.url}"
alt="{$row.field_slug_img.name}"
>
{/if}
</div>
{/foreach}
/SomeClass.php
function someMethod()
{
$dataRetriever = DataRetrieverFacade::getInstance();

$data = $dataRetriever->get($object); // Object
$data = $dataRetriever->get('product', $idProduct); // Entity and id

$elements = $data['field_group_slug']['field_group_slug'];

foreach($elements as $element) {
$value = $element['field_slug'];
..
}
}