According to the documentation here
https://payloadcms.com/docs/fields/overview#conditional-logicone should be able to access the User object in the condition - show/hide field based on user data.
When I copy the example into my code, I get the following error.
Type '(data: any, siblingData: any, { user }: { user: any; }) => boolean' is not assignable to type 'Condition<any, any>'
Is the documentation actual, or am I doing something wrong. Here is my code (inside tabs, inside row):
{
name: 'sourceAsset',
label: 'Offset Account',
type: 'relationship',
relationTo: 'assets',
admin: {
description: 'Some description',
condition: (data, siblingData, { user }) => { //<--- ERROR
return true;
}
},
access: {
create: isAssetManagerFieldLevel,
update: isAssetManagerFieldLevel,
read: isLoggedInFieldLevel,
},
filterOptions: ({ relationTo, data }) => {
return {...}
}
}
When I escape this error with ts-ignore, then I get the following runtime error:
caught (in promise) TypeError: Cannot read properties of undefined (reading 'user')
I'm currently also struggling with this
Within the condition type user is also not defined
export type Condition<T extends TypeWithID = any, P = any> = (data: Partial<T>, siblingData: Partial<P>) => boolean;
But it is included within docs and @dribbens added this from discussion
https://github.com/payloadcms/payload/discussions/2541with PR
https://github.com/payloadcms/payload/pull/2543Just to rule out the obvious, your Payload version is > 1.7.2, right?
The condition change should be in place for all field types. It has to be that you're on an older version of Payload as Tinouti suggested. If you're seeing this on @latest, I would create an issue on github.
@tinouti @dribbens thanks 🙏 and sorry, it was my mistake 🙈
I thought I was sure I had a version after this merge date 🤦♂️
Haha, glad to hear this was all this was! 🙌
@allannnc
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.