Last modified: Nov 10, 2024

Repeating groups

Setup for repeating groups

    Groups in the data model contain one or more fields. In the Layout configuration, a component is configured to be a repeating group by setting the type to "RepeatingGroup". A group that is repeating in the data model must also be set up as repeating in the form, if not, data saving will fail. In JSON, a repeating group is defined as an array of objects, where each object is a group. In XML, a repeating group is defined as a list of elements, where each element is an object with properties.

    Example

    Below is a form with a repeating group that:

    • Contains two components (checkbox and address)
    • Can be repeated up to three times
    • Is bound to the data model group/array GruppeListe

    Form with repeating group
    Form with repeating group

     1{
     2  "$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/layout/layout.schema.v1.json",
     3  "data": {
     4    "layout": [
     5      {
     6        "id": "gruppe",
     7        "type": "RepeatingGroup",
     8        "children": [
     9          "avkrysningsboks",
    10          "adresse"
    11        ],
    12        "maxCount": 3,
    13        "dataModelBindings": {
    14          "group": "GruppeListe"
    15        }
    16      },
    17      {
    18        "id": "avkrysningsboks",
    19        "type": "Checkboxes",
    20        "textResourceBindings": {
    21          "title": "Avkrysningsboks"
    22        },
    23        "dataModelBindings": {
    24          "simpleBinding": "GruppeListe.Avkrysning"
    25        },
    26        "options": [
    27          {
    28            "label": "Navn",
    29            "value": "Verdi1"
    30          },
    31          {
    32            "label": "Adresse",
    33            "value": "Verdi2"
    34          }
    35        ],
    36        "required": true
    37      },
    38      {
    39        "id": "adresse",
    40        "type": "Address",
    41        "dataModelBindings": {
    42          "address": "GruppeListe.Adresse",
    43          "zipCode": "GruppeListe.Postnr",
    44          "postPlace": "GruppeListe.Poststed"
    45        },
    46        "simplified": true,
    47        "readOnly": false,
    48        "required": true
    49      }
    50    ]
    51  }
    52}
    

    Parameters

    ParameterRequiredDescription
    idYesUnique ID, same as ID on other components. Must be unique in the layout file, and should be unique across pages.
    typeYesMust be ‘RepeatingGroup’
    dataModelBindingsNoMust be set for repeating groups with form components inside. Should point to the repeating group in the data model.
    textResourceBindingsNoCan be set for repeating groups, see description.
    maxCountNoThe number of times a group can repeat.
    minCountNoValidation. The minimum number of times a group must repeat before the user can submit the form.
    childrenYesList of the component IDs that are to be included in the repeating group.
    editNoOptions for how to display the group when editing a row.
    tableHeadersNoList of components that are to be included as part of the table header fields. If not specified, all components are displayed.
    tableColumnsNoObject containing column options for specified headers. If not specified, all columns will use default display settings.
    stickyHeadersNoIf set to true, the table headers will be sticky.

    textResourceBindings

    It is possible to add different keys in textResourceBindings to overrule default texts.

    • title - title to show above the group and over each group row in a Summary component.
    • summaryTitle - If set, overrides title when displaying a Summary component.
    • description - A description to show above the group beneath the title.
    • add_button - is added at the end of the “Add new” text on the button, and can be used to e.g. get text that says “Add new person”.
    • add_button_full - is used as custom text on the “Add new” button. Overrides add_button if both are set.
    • save_button - is used as text on the “Save” button when the user is filling out data.
    • save_and_next_button - is used as text on the “Save and open next” button if enabled.
    • edit_button_open - is used as text on the “Edit” button on the table when the user is opening an element.
    • edit_button_close - is used as text on the “Edit” button on the table when the user is closing an element.

    Groups in the data model contain one or more fields. Groups are defined as repeating if they have maxCount > 1 in the layout configuration. A group that is repeating in the data model must also be set up as repeating in the form, if not, data saving will fail. In JSON, a repeating group is defined as an array of objects, where each object is a group. In XML, a repeating group is defined as a list of elements, where each element is a group/object with properties.

    Example

    Below is a form with a repeating group that:

    • Contains two components (checkbox and address)
    • Can be repeated up to three times
    • Is bound to the data model group/array GruppeListe

    Form with repeating group
    Form with repeating group

     1[
     2  {
     3    "id": "gruppe",
     4    "type": "Group",
     5    "children": [
     6      "avkrysningsboks",
     7      "adresse"
     8    ],
     9    "maxCount": 3,
    10    "dataModelBindings": {
    11      "group": "GruppeListe"
    12    }
    13  },
    14  {
    15    "id": "avkrysningsboks",
    16    "type": "Checkboxes",
    17    "textResourceBindings": {
    18      "title": "Avkrysningsboks"
    19    },
    20    "dataModelBindings": {
    21      "simpleBinding": "GruppeListe.Avkrysning"
    22    },
    23    "options": [
    24      {
    25        "label": "Navn",
    26        "value": "Verdi1"
    27      },
    28      {
    29        "label": "Adresse",
    30        "value": "Verdi2"
    31      }
    32    ],
    33    "required": true
    34  },
    35  {
    36    "id": "addresse",
    37    "type": "AddressComponent",
    38    "dataModelBindings": {
    39      "address": "GruppeListe.Adresse",
    40      "zipCode": "GruppeListe.Postnr",
    41      "postPlace": "GruppeListe.Poststed"
    42    },
    43    "simplified": true,
    44    "readOnly": false,
    45    "required": true
    46  }
    47]
    

    Parameters

    ParameterRequiredDescription
    idYesUnique ID, same as ID on other components. Must be unique in the layout file, and should be unique across pages.
    typeYesMust be ‘Group’
    dataModelBindingsNoMust be set for repeating groups with form components inside. Should point to the repeating group in the data model.
    textResourceBindingsNoCan be set for repeating groups, see description.
    maxCountYesThe number of times a group can repeat. Must be set to 1 or more for the group component to work as a repeating group.
    minCountNoValidation. The minimum number of times a group must repeat before the user can submit the form.
    childrenYesList of the component IDs that are to be included in the repeating group.
    editNoOptions for how to display the group when editing a row.
    tableHeadersNoList of components that are to be included as part of the table header fields. If not specified, all components are displayed.
    tableColumnsNoObject containing column options for specified headers. If not specified, all columns will use default display settings.

    textResourceBindings

    It is possible to add different keys in textResourceBindings to overrule default texts.

    • title - title to show above the group row in a Summary component.
    • add_button - is added at the end of the “Add new” text on the button, and can be used to e.g. get text that says “Add new person”.
    • add_button_full - is used as custom text on the “Add new” button. Overrides add_button if both are set.
    • save_button - is used as text on the “Save” button when the user is filling out data.
    • save_and_next_button - is used as text on the “Save and open next” button if enabled.
    • edit_button_open - is used as text on the “Edit” button on the table when the user is opening an element.
    • edit_button_close - is used as text on the “Edit” button on the table when the user is closing an element.