Setting a dropdown when only one dynamic option exists

I feel like this is a common use case but I’m struggling.

I have two dynamic dropdowns. The first determines the scope of the second, like how selecting the make of a car will then define a list of models.

What I want to do is, if there is only one model, select that one in the second dropdown automatically. In terms of user experience it’s silly to make the user choose a model from the dropdown if there is only one.

But I’m not seeing how to do this. I want to set the default, but I see no way to do that conditionally, when there is only one result. My other thought is I could cheat a little and always have the first query result be the default, and if there are more options the user simply changes it.

In my case the parent category is “Carrier” which has-one-or-many “Power Units”.

You can set the Default Value conditionally…

So use a conditional with the same datasource as your dropdown:

When <search for powers: owned by = nav Dropdown Carrier's Value>: count is 1

Default value = <search for powers: owned by = nav Dropdown Carrier's Value>'s First Item

1 Like

Ah thank you. I had it in my head that conditionals were strictly UI type stuff. I didn’t realize it extended to data-related properties.

1 Like

Hi. I have a similar use-case and what you suggested is what came to my mind too. However, I wanted to check if this will result into multiple queries being fired for a small silly thing that could be handled by front-end.

The source of the dropdown has same ‘search for’, and then here in the conditional the same query is being called twice. It is possible that Bubble might be doing some optimisation about not running the same query multiple times, but don’t know if there is any official word on that. Would you know?

No, it won’t (but you can check that for yourself in your browser’s Dev tools…)

It is possible that Bubble might be doing some optimisation about not running the same query multiple times, but don’t know if there is any official word on that. Would you know?

Yes, Bubble is very clever when it comes to optimising searches… if the same ‘do a search for’ expression is used multiple times on a page, it will only actually be called once…

This is explained ‘officially’ in the Bubble manual:

If a page has the same search in more than one place, Bubble will automatically combine them to run the query once

Performance & Scaling - Bubble Docs

…and, again, it’s easy to check for yourself to see where/when/how searches are being made in the ‘Network’ tab of your browser dev tools (and worth doing whenever you’re trying to optimise your pages)

Thank you very much @adamhholmes for clarification and pointing to the documentation. Helps great deal.

Yeah browser dev tool is something I haven’t been able to use as much as I would want to. Will check that out more often probably, now.