Can’t use payload in admin.condition
function of field, can’t use async/await, can’t create options for select field dynamically
#7358
Replies: 3 comments
-
Hey @robinscholz — right now, this is deliberate, but I think we could potentially change this in the future. The thing is that conditional logic runs very frequently and should be heavily optimized so that your UI doesn't slow down. Generally, querying on data in a condition will add latency to the function and that would slow down the reactivity of the conditions themselves. Instead, what we normally do here is add a virtual field to the field schema that you need to run your condition against, and in that virtual field, populate the Does that make sense? I will convert this to a Feature Request so that we can evaluate others' interest in supporting the Local API inside conditions, but generally, you probably don't want to do this. You want to find a pattern to fetch that related data one time, and then use it accordingly rather than fetching it every time the condition runs (which is a lot). |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick reply! Seems like I am running into a different bug when trying to use payload to populate a virtual field.
In general I’d argue that the best solution for the select field would be if the select field options could take a function that has access to data as well as sibling data and maybe the user just like the conditions function. On top of that it’d be great if I could configure how deep the data would be unraveled, either globally in the payload config or even better granularly for that field. Not sure how feasible this would be with the current architecture though. Anyways, appreciate the lengthy answer regarding the topic! |
Beta Was this translation helpful? Give feedback.
-
heyho, just wanted to hop in here - i know this discussion aged a bit but now with the release of the 3.0 version maybe this feature-request can be looked at again? I stumbled upon this as I wanted to request the uploaded media to check the mimeType if it's video or image. To have a collapsible shown with video controls if mimeType is the video one. Would be cool if someone can have a second look here after the time was passing a bit :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Link to reproduction
No response
Payload Version
beta
Node Version
20.15.1
Next.js Version
15.0.0-rc.0
Describe the Bug
We are trying to either conditionally render the options of a select field or render the whole field conditionally based on siblingData from a relationship field. Since the siblingData only show a number for the relationship field, we would need to fetch the related collection entry to get its “slug” to decide if the field should be rendered.
The options seems to be static, so we tried to create multiple fields for each set of options and render them conditionally. Sadly the information given within the condition function arguments is not sufficient. It also appears that the condition field won’t take an async function.
Another solution would be if payload would allow the depths of the given data and sibling data to be configured somehow.
Reproduction Steps
Adapters and Plugins
No response
Beta Was this translation helpful? Give feedback.
All reactions