Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Conditional Admin Descriptions

default discord avatar
theduncolast year
13

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.

  • default discord avatar
    notchrlast year

    @thedunco What about having a custom field type that acts as a description. Then conditions would be able to show/hide that

  • default discord avatar
    theduncolast year

    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

    .

  • default discord avatar
    notchrlast year

    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

  • discord user avatar
    jmikrut
    last year

    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

  • default discord avatar
    theduncolast year

    Yeah, maybe I'll have some time this weekend to give this a shot!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team..