Dynamic dropdown lists

Hey,

i’m trying to “optimize” my app a little bit and need your help.

I have a few questions for the user whose values all come from the database.

The user first selects a year, 1965-1970. Depending on the selected year, the following dropdown list should show other data from the database. There is a database table for when the user chooses 1965, 1966…and so on

I also tried to draw this, no idea if this helps with understanding.

grafik

What is the best way to achieve this?

I honestly would have gone now and made a separate dropdown for each year and a workflow that selects a different dropdown depending on the selection. But that sounds very inefficient.

Hi there, @bubble.io.mails… if you don’t need users (i.e., anyone on the front end) to be able to add values to the dropdowns, you could consider using an option set with an attribute on the set that stores the year associated with each option. Then, defining the options for a dropdown is as easy as getting the options from the set filtered to the ones that have a specific year as their attribute.

Hope this helps.

Best…
Mike

1 Like

Hey Mike,
thanks for your reply. I’m kinda lost there to be honst. Do you know if i can find it somewhere detailed in like a…step by step guide or in the docs?

Thanks!

BR

There is a ton of info out there on option sets, but it might be difficult to track down something that details exactly what you are trying to do. So…

Add an option set for the years.

Then, add another option set and give it an attribute for year.

As you define the options in the set above, click the Modify attributes link beside each option and enter the associated year in to the year attribute field.

Next, add a dropdown to a page that displays the years from the years option set.

dropdown_years

Finally, add another dropdown to display the options from the other set filtered by the year that is selected in the first dropdown.

2 Likes

Wow, thank you very much for taking the time to do all that. I really appreciate it!

But I guess this isn’t really an option for large/many data sets right?

This is a fraction of the tables that i have:

The current idea is to ask the user like that:

1964 → dropdown1 → dropdown2 → dropdown4 → dropdown5 ->dropdown6
1965 → dropdown1 → dropdown2 → dropdown4 → dropdown5 ->dropdown6
1966 → dropdown1 → dropdown2 → dropdown4 → dropdown5 ->dropdown6
1967 → dropdown1 → dropdown2 → dropdown4 → dropdown5 ->dropdown6

Almost all the dropdown fields are different, depending on the year the user chose.

Which means that i would have to do the option set for every single one of those and can’t use a bulk import or something like that?

It kinda feels like it would be the better idea to create a rest api or something like that to have a more dynamic approach.

Well, there is this…

But given your requirements, you are probably better off going with custom data types or some other option.

Hey, thanks! I guess that i will create different workflows…for each year individually, depending on the year input the user chose.

Thing is: I will work with “hidden” dropdown lists and will only make them appear through the workflow.

Would you say that this is “bad practice” having like 30 hidden boxes on the page? It’s just a hobby project but im wondering if this could impact the site performance.

This topic was automatically closed after 70 days. New replies are no longer allowed.