Why do repeatable groups insist on being initialized with at least one null item?

Hello,

I have a doc type that contains a repeatable group representing links. It contains two key text fields called "text" (what will be displayed for the link) and "url" (where the link will take you when clicked):

When I create a new document based on this type, it insists on populating the group list with at least one link with null for text and url:

Why is this?

This is forcing me to check that the text or url have actual values in my code since I cycle through the links in a foreach loop. I was expecting that it would skip the foreach loop if the Prismic content editor had no links to add to the document, but because it is initialized with at least one, it enters the foreach loop and I have to check.

I realize I can just easily delete the default link on creating new documents, but is there a way to set it so that it leaves the list initially empty? That way, I don't have to worry about content editors not knowing to delete the default link.

Thanks.

1 Like

Hello,

Thank you for contacting us.

Currently, by default, at the time of document creation, group field will have one list item inside it, which will return null, this is the expected behaviour of the API response. To get the empty list, only option is to delete this list item in the group field, as you are already doing. I'd suggest to you use slices instead group to avoid this issue.

Although, we will consider this as part of our future developments as it's a good idea to have an empty list in a repeatable group field by default.

Thanks,
Priyanka

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Hey I just thought I'd bump this up and see if this is being considered. Maybe this could be an option instead of a default with no control over it.

I'm setting up some taxonomies with groups of content relationships, and some of them will be empty for some of the documents, so it makes no sense to have to clear this out every time. Also, I can't really replace content relationships with slices, because I need these to do specific queries.

Just hoping this is still on your radar as something to address!

Hello @Christopotamus

Thanks for jumping here and voting on this feature for future development. We are tracking it as a feature request but no ETA.

Thanks,
Priyanka