Can we use a field value entered by the user to generate another field value in the same collection? Example: User entered a value in full name field, can we use the this value to fetch the first name ?
You can perform this type of operation with a field hook. Here is an example of a beforeChange hook to populate a
firstName
field by splitting the
fullName
value.
{
name: 'fullName',
type: 'text',
hooks: {
beforeChange: [
({ data, value, operation }) => {
data.firstName = typeof value === 'string' ? value.split(' ')[0] : '';
return value;
},
],
},
},
{
name: 'firstName',
type: 'text',
},
Star
Discord
online
Get dedicated engineering support directly from the Payload team..