If using list options on a string field, how do you access the ‘title’ in the preview? #3906
Answered
by
joaisa17
spacedawwwg
asked this question in
Sanity Studio Support
-
if using list options on a string field, how do you access the ‘title’ in the preview? e.g. the stored value is uk but I’d like to display United Kingdom (this is the default in V2 actually) |
Beta Was this translation helpful? Give feedback.
Answered by
joaisa17
Dec 6, 2022
Replies: 1 comment
-
Here's a fix that works: const list = [
{ value: 'japan', title: 'Japan' },
{ value: 'us', title: 'United States' },
{ value: 'uk', title: 'United Kingdom' },
{ value: 'eu', title: 'Europe' },
];
// Field
defineField({
name: 'region',
type: 'string',
title: 'Region',
options: { list }
})
// Preview
{
preview: {
select: { city: 'city', region: 'region' },
prepare: s => ({
title: s.city,
subtitle: list.find(r => r.value === s.region)?.title ?? 'No region'
})
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
spacedawwwg
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a fix that works: