Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

How to customize options text in relationship field?

default discord avatar
.pixelpoint8 months ago
4

I'm trying to use PayloadCMS with Postgres and stuck on relationship type of field. When I use it, it uses a primary key "id" as a text for options inside the dropdown, when I want title to be used instead. It feels like a bug specifically with Postgres, since based on all examples availalbe there should not be any extra code, however anyway I can't find a way to customizing these texts since it also feels like quite an obvious feature.

  • default discord avatar
    paulpopus8 months ago

    In your referenced collection are you setting up your

    admin.useAsTitle

    configuration?

    https://payloadcms.com/docs/configuration/collections#admin-options


    this is what tells the cms what field it can use as a preview/title

  • default discord avatar
    .pixelpoint8 months ago

    Perfect, thank you very much for very quick response. It helped. I think it would be great mentioning it inside Relationship documentation page.

  • default discord avatar
    paulpopus8 months ago

    For sure!

  • default discord avatar
    deankemball6 months ago

    i get this error:


    'useAsTitle' does not exist in type 'Admin'



    how did you implement it @pixelpoint ?


    this is my config:


     {
          name: 'artist',
          label: 'Artist',
          type: 'relationship',
          relationTo: 'artists',
          admin: {
            sortOptions: 'name',
            useAsTitle: 'name',
          },
        },
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team..