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 the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?