Skip to content

If using list options on a string field, how do you access the ‘title’ in the preview? #3906

Discussion options

You must be logged in to vote

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'
        })
    }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by spacedawwwg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants