Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

How to Return the Title and not the Value of a String or List

5 replies
Last updated: Mar 15, 2021
Super basic one, need to return the
title
and not the
value
of a
string/list
but it appears way harder than it should be... I must be missing something?
Mar 15, 2021, 12:46 PM
*[_type == "document" && _id == '12345'][0]{
    'breaksOver': brk_breaksover
}
Mar 15, 2021, 12:47 PM
I'm afraid the title is not recorded but just there for the select options in the studio. The value is what's actually set on the field.
Mar 15, 2021, 1:00 PM
If you need an actual title/value combination in your data, you could consider creating a custom input component that sets both the title and the value or using a reference field to a separate document type that holds the different options. The advantage of the last approach is that you can easily update titles and values at any time. The downside is having an extra document type just for this purpose.
Mar 15, 2021, 1:04 PM
Ahh okay, that is a little awkward... assumed this would have been an obvious capability. Maybe I missed that in the docs? It would be a helpful to have a note if it's not already there. Will check alternatives, though will likely just get creative on the front-end. Thanks for letting me know! šŸ¤™
Mar 15, 2021, 1:07 PM
Getting creative on the front-end sounds like a good way to take care of this as well šŸ˜‰ Noted your docs idea, thanks!
Mar 15, 2021, 1:10 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?