'Prismic - set a maximum for repeatable elements in group

Is it possible to only allow content creators to add 1 or 2 elements in a repeatable group? I am looking for something like this:

     "content_teasers" : {
        "type" : "Slice",
        "fieldset" : "Content Teasers",
        "description" : "One or two teasers with Image, Title, Text and an optional link",
        "repeat": 2,
        "repeat" : {
          "image" : {
            "type" : "Image",
            "config" : {
        [...]

where "repeat": 2 sets the number of allowed elements.



Solution 1:[1]

No, it's not possible, The way to do it today would be to add the fields in the non-repeatable section of a slice. I'm part of Prismic's team so I just logged this as a feature request for the dev team! Is it because you have strict design rules of having X number of components? or you don't want to handle the display of too many cases (if they put 1, 2, or 10 items?)

Solution 2:[2]

I've recently run into a similar problem but found a hacky solution that's been working for me (still hoping something is officially added to Prismic). If you add the number of items you want to your page before you add "repeat": false to your JSON config, it will keep those items but remove the ability to add more.

For anyone who comes across this, here's a snippet from one of my custom types as an example:

{
  "Main": {
    "title": {
      "type": "Text",
      "config": {
        "label": "Title"
      }
    },
    "uid": {
      "type": "UID",
      "config": {
        "label": "uid"
      }
    }
  },
  "Hero": {
    "hero_images": {
      "type": "Group",
      "config": {
        "repeat": false,
        "fields": {
          "image": {...}
        }
      }
    }
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nounou
Solution 2