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.

Conditionally render field options

default discord avatar
theod0re.2 years ago
3

I have a collection of

categories

. Each category has an array field with

subcategories

. I have another collection

posts

with fields of

category

and

subcategory

. I have specified that the category field is related to the categories collection. However, how could I conditionally render the options for the subcategory field once a category has been chosen?

admin: { condition }

only allows me to show or hide the filed but not to render its options based on a payload request that uses the data from the previous field.

  • discord user avatar
    denolfe
    2 years ago

    Have you taken a look at the field conditional logic docs here?

    https://payloadcms.com/docs/fields/overview#conditional-logic

    . This should support dot notation which will help for your use-case.

  • default discord avatar
    gaurav00342 years ago

    I also have same problem if you solved this issue can you please tell me how I do this



    i have same problem I am using payloadcms and in collection of posts I have


    {


    name: "category",


    type: "relationship",


    relationTo: "categories",


    required:true


    }, this category field , now I want to include subcategories field but it should show subcategories only from array which is present in selected category



    I have subcategories collection from that collection only I am currently getting subcategories using relationship but now I want subcategories according to selection of category can you please help or guide with this



    My question is i have collection categories and collection subctegories, in categories collection i added subcategories throughe relationship, so while creating any post i need that my subcategories should populate in option depending upon selection of cetegory.But i am not able to do that so please help me with that

  • default discord avatar
    whysocketlast year

    same problem here

    @831954168923160596

    .


    Have you fixed that?

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.