use a group field for useAsTitle

default discord avatar
Teelon
last year
1 1

Can I use a group field for the useAsTitle on a collection admin property?. As of now it takes String? which indicates the field name that you want to use.
{ name:'name', type:'group', fields:[ { name:'first', type :'text' }, { name:'last', type:'text' } ] }

  • discord user avatar
    JarrodMFlesch
    Payload Team
    last year

    To be clear, you are wanting to use first as the document title?

    No that is not currently possible. What you could do instead is create a top level field i.e. fullName and use a field hook to update that based on name.first and name.last.

    Something like this:

    {
      slug: 'example-collection',
      admin: {
        useAsTitle: 'fullName',
      },
      fields: [
        {
          admin: {
            hidden: true,
          },
          name: 'fullName',
          type: 'text',
          hooks: {
            beforeChange: [
              ({ siblingData, operation, value }) => {
                if (operation === 'create' || operation === 'update') {
                  return `${siblingData.name.first} ${siblingData.name.last}`
                }
                return value
              },
            ],
          },
        },
        {
          name: 'name',
          type: 'group',
          fields: [
            {
              name: 'first',
              type: 'text',
            },
            {
              name: 'last',
              type: 'text',
            },
          ],
        },
      ],
    },
Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.