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.
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.
Yes. Every record has one single country, not multiple.
selectbyuuid is pointing to the actual record I´m going to edit.
Selectbyuuid is currently a list. It might be a list containing a single item, but it is still classed as a list.
:first item operator to turn the list into a single item.
It appears that the system doesn’t accept any default value aside from referencing the option sets.
:Country to select the record’s optionset. The expression should be
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.
I tried both:
selectbyuuid_location:first item´s Country
The error message is still telling to refer to the option sets…
What is the datafield type of ‘Country’. Is it a text or is it a pointer to the Country (OS) option set?
The data field on the column Country in my database is text.
In the dropdown it´s a pointer to the option set.
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.
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.
Thanks @nico.dicagno !
I´m not sure how I can change the type to be the Option Set itself ? I guess I need to change something in my query then?
I tried to add the constrain you gave me.The only possible option I have turning blue is the one in the picture.
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’
Thank you so much! You solved it!
One more thing. Is it possible to do the same when using an external database also for the source:
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.
What default valu would you like to set?
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.
@nico.dicagno I tried this. It turns blue. But I´m not seeing any default value. Can you point me in the right direction?