Is it possible to make a conditional admin description? Looking at the
descriptiontypes, it looks like it can be passed a React component, but none of the types seem to pass along
siblingDatato the function/component which I would need to do this. Is there a way to create a React component that knows about the current
siblingDatastate 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.
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
siblingDatainfo 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
Descriptioncomponent the
pathof the field
that way, you could use the form methods to retrieve
siblingDatawe would not want to just pass in
siblingDataitself, 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)
sounds like a good PR to make
what you'd wanna do is:
1. modify the props of our built-in
FieldDescriptioncomponent to require the passing of
path2. locate all instances of
<FieldDescriptionand update it so that you pass the
pathinto it
3. update the
descriptiontype to take a
pathin addition to the
valuethat 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.