1

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.

Bergrebell
  • 4,263
  • 4
  • 40
  • 53

2 Answers2

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?)

Nounou
  • 67
  • 2
  • we have strict design rules and i guess it could be quite confusing for content creators if they could enter more elements than we display at the end. – Bergrebell Mar 13 '20 at 07:48
1

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": {...}
        }
      }
    }
  }
}
ryjohnson
  • 45
  • 5