#Custom label in the relationship dropdown | Payload CMS 3.0

7 messages · Page 1 of 1 (latest)

toxic cargo
#

Hello I have a relationship, connecting cars' collection with bookings' colleciton, the only problem I face is that I can't update labels inside the dropdown which is displayed in the "bookings" collection. Since my client has more than 1 model for each car brand it's extremely unintuitive to display just the car manufacturer's name. Is there a way for me to customize this? Help would be much appreciated!

Uploaded images for the clarity:

tranquil sail
#

What I do in these cases is I create a new field on the collection (in your example car) which I call title. I create it hidden and with a hook to update it automatically:

        {
            name: 'title',
            label: 'Tittel',
            type: 'text',
            admin: {
                hidden: true,
            },
            hooks: {
                beforeValidate: [
                    (({ data, value }) => {
                        if (data) {
                            return [data.name, data.model].filter(Boolean).join(' - ');
                        }
                        return value;
                    }) as FieldHook<Car, string>,
                ],
            },
        },

Then in the collectionconfig of car you set this new field as the title:

    admin: {
        useAsTitle: 'title'
    }

Then this new field will be used as the title, but not shown in the editor itself.

toxic cargo
#

Thanks mate! Looks much better now!

#

@tranquil sail

tranquil sail
#

🙌