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' } ] }
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',
},
],
},
],
},
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.