I’m integrating an external database with Bubble, and I’ve encountered an issue with setting default values for certain fields.
I’ve successfully implemented default values for input fields and dropdowns using a single query. However, I’m facing challenges when trying to set default values for fields that require combining two queries or involve a query and an options set.
For instance, I’ve attached an image below as an example of the scenario I’m dealing with. As you can see, I’m trying to combine one query with an options set, and I’m unable to set a default value pointing to my database.
If anyone has experience with this or can provide guidance on how to approach setting default values in such scenarios, I would greatly appreciate your assistance.
Hi Rallis,
In the screenshot attached it seems like you are trying to set a list of Country’s as a default value. The default value needs to be a single value, not a list.
Maybe use :first item?
If your usecase allows multiselection (ie a dropdown where you can select multiple items) you can either build a custom one yourself using a group, group focus, and a custom state list, or you could use a plugin. There is a multiselect dropdown built by Bubble called :drumroll: Multiselect Dropdown. That might help!
This pertains to an edit form designed for the modification of previously registered entries in my database.
I’m employing Option Sets to present the available choices (countries) in a dropdown. However, I aim to set the default value to be the country already submitted and listed in the record within my database.
Does the record in your database contain a single Country, or does it contain a list of countries?
Is selectbyuuid supposed to be your database record?
The main problem is that you are trying to set the default value a list instead of single item.
Add :Country to select the record’s optionset. The expression should beselectbyuuid_location:first item:Country
This is because the dropdown expects Countries as possible choices, not a database record.
In general it would also be better to set the customstate ‘selectbyuuid_location’ to a non-list custom state if there is no reason for it to be a list.
Thats the problem then. It would be better if its type were the Option Set itself. This would allow you to reference the Option Set directly.
If you really don’t want to change the type of the field (that would require you to create a new field) you can still get stuff to work.
Use:
Get an option set >> select the type as Country (OS) >> all options >> filtered >> Constraint: This Country’s display is selectbyuuid_location:firstItm:Country >> first item
This works, but its not very fast because filtering takes a bit of time.
Sadly you cannot change the type of a datafield after its creation. You will have to create a new data field and replace all references of the old data field to the new one.
The app search tool is very useful to find all references of datafields. You can find it on the top right side of the window, it looks like a magnifying glass.
The ‘choices source’ you had put originally was correct. (All Countries ios)
The expression i gave you was for the default value. And remember to add first item; ‘All Countries (ios): filtered :first item’
Yes, you just have to make sure that the default value is of the same Type as the Choices sources. So in this case it would have to be a single Select_db_location, it cannot be a list.
The chosen individual in the record reflects a comparable situation. Specifically, I aim to modify a record obtained from “select_dbo_location,” diverging from the conventional option set. This record is sourced from “selectbyuuid_facility.” The specific item I seek to configure is the pre-selected Location within the record.