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 rendering options within a second select field based on the value of the first

default discord avatar
hristo60049 months ago
2

Hey guys, wondering how to go about this.



Basically I'd like to have two select fields, where the options in the second depend on the first. Let's say in the first I'm selecting countries and in the second - cities.



I can add

admin.condition

to the second field, but I'm wondering if it's possible to add condition to the option itself within that field.



With the current setup, I'll need to have a new

select

field for each option from the first field, rather than keeping the select field and have dynamic options. It'll result in this:

countries

,

cities_Gb

,

cities_Fr

,

cities_Es

, etc. Ofc that's just an example and thankfully I'm not doing THAT. 😄 But I'd like to keep only

cities

.



I could always build my own component as well, I guess. But wondering if there's something I'm missing. Thanks!



I see, thanks for confirming. I guess I'll have to do it with a custom component. 🙂

  • default discord avatar
    Payload-Bot10 months ago


  • default discord avatar
    ritsu045510 months ago

    There's no way to set select options dynamically currently if you mean this. Only through a custom component.


    Your custom component can access the data with

    useFormFields

    hook, then you basically should forward all the props to the default

    SelectField

    while overriding

    options

    prop.

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.