Customizable Display Names for Relationship Fields #12585
kodermax
started this conversation in
Feature Requests & Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Add the ability to define custom display names for relationship fields in Payload CMS by combining multiple fields, instead of relying solely on the useAsTitle property.
Problem
Currently, the useAsTitle property in Payload CMS allows only a single field to be used as the display name for relationship fields in the admin UI. This limitation can be restrictive when users need a more descriptive or context-specific title that combines data from multiple fields (e.g., combining firstName and lastName for a user, or title and date for an event). This results in less intuitive selection experiences in the admin interface.
Proposed Solution
Introduce a new configuration option for relationship fields, such as displayFields, that allows users to specify a combination of fields to generate a custom display name. This could be implemented as:
A displayFields array to list fields to combine (e.g., ['firstName', 'lastName']).
An optional format function or template string to define how the fields are combined (e.g., '{{firstName}} {{lastName}}' or a function returning a formatted string).
Fallback to useAsTitle if displayFields is not specified, ensuring backward compatibility.
Example Configuration
Example Output
In the admin UI, instead of showing only the useAsTitle field (e.g., "John"), the relationship field dropdown could display "John Doe" by combining firstName and lastName.
Benefits
Improved UX: More descriptive display names make it easier for editors to identify related records.
Flexibility: Users can tailor the display to their specific needs without modifying the schema structure.
Consistency: Aligns with common CMS patterns where relationship fields can show combined field values.
Use Cases
Displaying full names (firstName + lastName) for user relationships.
Combining title and date for events or posts (e.g., "Annual Meeting - 2025-05-28").
Creating unique identifiers by combining fields like sku and productName for products.
Backward Compatibility
Ensure the new displayFields and format options are optional, defaulting to the existing useAsTitle behavior if not specified.
Additional Notes
Consider performance implications when fetching and formatting data for large collections.
Provide validation to ensure displayFields references valid fields in the related collection.
Allow localization support for the format function to handle different languages or formatting conventions.
This feature would significantly enhance the flexibility and usability of relationship fields in Payload CMS, making it easier for users to work with related data in a more meaningful way.
Beta Was this translation helpful? Give feedback.
All reactions