change field that is displayed in relationship field dropdown

default discord avatar
br0nce10 months ago
3
const Tag: CollectionConfig = {
  slug: 'tags',
  fields: [
    {
      name: 'product',
      type: 'relationship',
      relationTo: 'products',
      required: true,
    },
    {
      name: 'date_given_out',
      type: 'date',
      required: true,
    },
  ],
};
export default Tag


With this code, the dropdown will display the Id of my products. I want

product.name

to be displayed instead. I couldn't find in the documentation where to set this.

  • default discord avatar
    christianjmay10 months ago

    @𝗕𝗿𝗼𝗻𝗰𝗲 if you want the name to be used across payload to identify documents in that collection, you can set

    admin.useAsTitle

    in its collection config:

    https://payloadcms.com/docs/configuration/collections#admin-options
  • default discord avatar
    br0nce10 months ago

    Thanks!

  • default discord avatar
    christianjmay10 months ago

    you're very welcome!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

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