Get a peek at our latest innovations at Sanity Product Day on Dec 8th →

List Arrays - Is it Possible to Fill a List Array Within a Schema Asynchronously?

2 replies
Last updated: Mar 16, 2021

Is it possible to populate a list array within a schema asynchronously with another document type as options? I’m trying to make a series of dynamic grouped categories more accessible to apply to a document as filters. It’s not easy to search them with an array of references as the parent element (the name of the category group) doesn’t show up, and category groups contain many categories with vague names which are sometimes shared across groups e.g.

categoryGroups: ["size", "width"]
both with a category
medium
.

Mar 16, 2021, 3:02 PM

I asked Knut about this a few weeks ago and you’d need to use a custom input. This thread was recently suggested so maybe it’s something that will make its way into references some time soon.

Mar 16, 2021, 3:26 PM

Hmm thanks

user A
! It’s a tricky one at present. I’ve not much custom input experience, beyond messing with the unicorn example for lols. I guess the best way to handle my specific case would be to keep an array of references within the schema, then define a custom input component which handles their presentation differently e.g. as a series of category checkboxes grouped by title.

Mar 16, 2021, 3:31 PM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Free to get started, and pay-as-you-go on all plans. Find out more.