Hello everyone, I am a newbie
in collections,I create a c.ts,it contain C1,C2,C3,Now I wanna make c3=c1+c2,how to get c1,c2 value in c3's hook, pls help to how to do it,thanks,
my code is below:
`
import { CollectionConfig, Field } from 'payload/types';
const Tags: CollectionConfig = {
slug: 'c_sum',
admin: {
useAsTitle: 'name',
defaultColumns: ['name', 'c1','c2','c_sum']
},
access: {
read: () => true,
create:()=>true,
},
fields: [
{
type: 'text',
name: 'name',
},
{
type: 'number',
name: 'c1',
label: "c1",
},
{
type: 'number',
name: 'c2',
label: "c2",
},
{
type: 'number',
name: 'c_sum',
label: "c_sum",
},
],
timestamps: false,
}
export default Tags;`
i solved:
{
type: 'number',
name: 'c_sum',
label: "c_sum",
admin: {
description: 'c1+c2',
hidden:false
},
access: {
update: () => false,
create:()=>false
},
hooks: {
afterRead: [
({ data }) => {
return data.c1 + data.c2;
}
],
},
},
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.