# Limit some blocks in the repeater

**URL:** <https://discourse.getcockpit.com/t/limit-some-blocks-in-the-repeater/1288>\
**Category:** Support\
**Created:** [March 23, 2020, 1:39pm UTC](https://discourse.getcockpit.com/t/limit-some-blocks-in-the-repeater/1288 "2020-03-23T13:39:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alessandro92](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@alessandro92](https://discourse.getcockpit.com/u/alessandro92)\
**Post date:** [March 23, 2020, 1:39pm UTC](https://discourse.getcockpit.com/t/limit-some-blocks-in-the-repeater/1288/1 "2020-03-23T13:39:37Z")

</div>

Hello to all,  
i have a repeater block where you can select 3 blocks:

- Project
- Text
- Services

Is it possible to limit the Services block to 1 in the entire repeater?

For example, I would like to give the possibility to insert many project blocks and many text blocks but only one service block.

```
{
  "fields": [
{
  "type": "set",
  "label": "Project",
  "options": {
    "fields": [
      {
        "type": "select",
        "name": "layout",
        "label": "Layout",
        "options": {
          "options": {
            "wide": "Wide",
            "half": "Half"
          }
        },
        "default": "wide"
      },
      {
        "type": "collectionlink",
        "name": "project",
        "label": "Project",
        "options": {
          "link": "projects",
          "display": "project_name",
          "multiple": false
        }
      }
    ]
  }
},
{
  "type": "set",
  "label": "Text",
  "options": {
    "fields": [
      {
        "type": "select",
        "name": "style",
        "label": "Style",
        "options": {
          "options": {
            "singlecol": "Single Coloumn",
            "multicol": "Multiple Coloumn"
          }
        },
        "default": "singlecol"
      },
      {
        "type": "wysiwyg",
        "name": "content",
        "label": "Text",
        "options": {
          "editor": {
            "toolbar": "undo redo | bold italic underline link |",
            "formats": {
              "underline": {
                "inline": "u",
                "exact": true
              }
            },
            "default_link_target": "_blank",
            "entity_encoding": "raw",
            "forced_root_block": "",
            "menubar": false
          }
        }
      }
    ]
  }
},
{      
  "type": "collectionlink",
  "name": "services",
  "label": "Services",
  "options": {
    "link": "services",
    "display": "name",
    "multiple": true
  }
}
  ]
}

```

Thanks

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [March 23, 2020, 6:40pm UTC](https://discourse.getcockpit.com/t/limit-some-blocks-in-the-repeater/1288/2 "2020-03-23T18:40:13Z")

</div>

No, that’s not possible. But you could split the field into two fields or into a surrounding set. The one with the services has a limit of one.

Alernatively you could write your own modified repeater field that checks against the existence of the services field.

---

<div class="post-metadata">

**Author:** ![alessandro92](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@alessandro92](https://discourse.getcockpit.com/u/alessandro92)\
**Post date:** [March 24, 2020, 8:24am UTC](https://discourse.getcockpit.com/t/limit-some-blocks-in-the-repeater/1288/3 "2020-03-24T08:24:01Z")

</div>

How can I write my repeater field?  
Is it possible to give an example?

Thanks

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [March 24, 2020, 1:45pm UTC](https://discourse.getcockpit.com/t/limit-some-blocks-in-the-repeater/1288/4 "2020-03-24T13:45:59Z")

</div>

You can copy the original repeater component from `/modules/Cockpit/assets/components/field-repeater.tag` into `/config/tags/field-repeater.tag` and change it here.

Now have a look at the `add` function. There you can add a check, if the items contain a service field already.

> <https://github.com/agentejo/cockpit/blob/next/modules/Cockpit/assets/components/field-repeater.tag#L100-L114>

If you need some more inspiration for creating custom fields, have a look at

> **[raffaelj/cockpit-scripts](https://github.com/raffaelj/cockpit-scripts/tree/master/custom-fields)**
>
> A collection of code snippets with annotations to modify Cockpit CMS - raffaelj/cockpit-scripts
