👀 Our most exciting product launch yet 🚀 Join us May 8th for Sanity Connect

How to populate a list of predefined strings based on another field in the same document

2 replies
Last updated: May 24, 2023
Hey everyone,
I'm wondering if there is a way to populate a list of predefined strings based on the value of another field in the same document?

Basically what I'm hoping the achieve is this. I have a
collection
document that references
products
and the
collection
can conditionally have sub-categories which are just added as string tags. I was hoping to be able to add a
product
and be able to give it a sub-category based on the ones already defined in the
collection
. I've been able to get it so the editor can just type in a category and it will be invalid unless it matches one already defined in the sub-categories field but this seems a bit hacky. Any advice on how best to achieve this? Perhaps custom input component?
May 24, 2023, 6:29 AM
Nevermind. Figured out a solution myself using a custom input component as suspected 🙂
May 24, 2023, 12:11 PM
For anyone that’s also looking for how to do this, here is an example.
May 24, 2023, 7:20 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?