#Can you check a slug in a field condition?
11 messages · Page 1 of 1 (latest)
Are you asking about conditional fields?
https://payloadcms.com/docs/fields/overview#conditional-logic
You can get the slug in from the data passed to the condition function and return true or false based on that.
Yes! Great! Then we'll find a way! Thank you!
@harsh snow under the hood Payload slugifies the slug, so I believe you would check for data.slug === 'event'. You can console log the entire data object to see what it has attached to it as well!
even though I do it like this it won't neither log nor hide the group field I'm trying to hide
okay seems like data.slug is a falsey value because if I check for data.slug it returns false, I assume I need to have a field that is called slug in my collectionConfig to make this work? Is there any other way to check for the slug of the collectionConfig?
Is this an abstracted field that you are using in multiple collections? If that is the case, I would thread through the collection as a string all the way to the abstracted field!
Or even if you are using an abstracted field inside a block, then require the block to be passed the collection string, and thread/pass that down to the field as another argument 👍