👋 Next.js Conf 2024: Come build, party, run, and connect with us! See all events

Is it Possible to use a Field Value as the Title for an Object Field?

4 replies
Last updated: Apr 10, 2021
Is it possible to use a field value as the
title
for an
object
field being the main field of a document? In fact avoid this 😅
fields: [
        {
            name: 'content',
            type: 'object',
            inputComponent: Tabs,

            // Tabs
            fieldsets: [
                { name: 'details', title: 'Details' },
                { name: 'infos', title: 'Informations' },
                { name: 'content', title: 'Content' },
            ],
            options: {
                // layout: 'object'
            },

            // Fields
            fields: [
                /**
                 * Details
                 */
                {
                    name: 'title',
                    title: 'Project title',
                    type: 'string',
                    fieldset: 'details',
                    validation: Rule => Rule.required(),
                },

Apr 9, 2021, 9:29 PM
user N
You should be able to add a preview, and use the ‘select’ key to assign ‘mainTitle’ to the title (you can also define ‘subtitle’ and ‘image’ by default and even create your own react component to render the preview)
  preview: {
    select: {
      title: 'mainTitle',
    }
  }
(or
'content.mainTitle'
)
More on list previews here:

https://www.sanity.io/docs/previews-list-views
Apr 9, 2021, 9:41 PM
Oh nice! Thanks
user J
! Very new to Sanity sorry if that all sounds obvious haha
Apr 9, 2021, 9:43 PM
Not at all! there’s a lot of depth to the Studio customization
Apr 9, 2021, 9:45 PM
also, if the title is only for presentation in the studio, you can hardcode it like this:
Apr 10, 2021, 6:40 AM

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?