Is it possible to make a conditional admin description? Looking at the
description
types, it looks like it can be passed a React component, but none of the types seem to pass along
siblingData
to the function/component which I would need to do this. Is there a way to create a React component that knows about the current
siblingData
state of the form and can change the description text based on that?
I am aware that the pattern I've chosen that created this problem isn't a great one, but I'm locked in now so I'd like a way to do this.
@thedunco What about having a custom field type that acts as a description. Then conditions would be able to show/hide that
Oh I suppose that could work as well. And then use the React hooks and/or props if they get passed in to get the
siblingData
info I need?
I have "solved" this in my case by just having the description worded differently, so it's not a huge deal, but I feel like pretty much everything in the config should be able to accept a function that has access to
siblingData
.
Yeah agreed! I'm not sure about the hooks part, but it sounds like it should work?
I almost always use the siblingData versus data, as a side note
hmm
one thing we could do is pass the
Description
component the
path
of the field
that way, you could use the form methods to retrieve
siblingData
we would not want to just pass in
siblingData
itself, because we don't want to retrieve that unless we HAVE to
so i'd leave that to your custom component to leverage hooks to retrieve (which you could as long as you had the path)
@thedunco sounds like a good PR to make
what you'd wanna do is:
1. modify the props of our built-in
FieldDescription
component to require the passing of
path
2. locate all instances of
<FieldDescription
and update it so that you pass the
path
into it
3. update the
description
type to take a
path
in addition to the
value
that it takes now
4. update docs of course
Yeah, maybe I'll have some time this weekend to give this a shot!
Star
Discord
online
Get dedicated engineering support directly from the Payload team..