Format Dropdown Values as Numbers

I have dropdowns where the values are something like “3 Widgets”. When that value is selected, I want it to be interpreted as “3”, the number. How can I get the text string in dropdowns to be interpreted as numbers?

You could use a custom state: “When dropdown’s value is changed and this dropdown’s value is “3 widgets”> Set custom state (type number)'s value to 3.” You can use the value of the custom state from there.

OR you could save the value to a field: "When dropdown’s value is changed and this dropdown’s value is “3 widgets” > make a change to a Thing > field in Thing = 3. Now that value is saved to your database.

Let me know if this helps.


Gaby | Coaching Bubble

1 Like

Thanks for your response!

So I went into the dropdowns conditional tab, clicked “define another condition”, set the “when” field to This Dropdown’s Value is “3 widgets”. But when I click “Select a property to change in this state” I don’t see value as an option. I see "Default Value’ but I don’t think that’s what you’re referring to?

I’m sorry, I should have specified. These would both be workflows, not conditionals. So create a workflow “When input’s value is changed” and select the dropdown as the input. From there you can choose to use the custom state route (an element action) or the data change route (a data action).

1 Like

Thank you so much for all the help you’ve been. I wasn’t even aware of the custom states. Thanks!

1 Like

I’ve been working on this same issue for hours trying different methods and just cannot get there! Does anyone have a step-by-step for this? Always what’s shown as a guide everywhere is different from what is actually shown in Bubble… so I’m having a hard time understanding where I’m supposed to be adding these values, custom states, etc…

@catebligh, this thread is quite old, and at this point, you should definitely consider using an option set. You can make the options (display) whatever you want (such as “3 Widgets”), and you can add an attribute (number) to the option set so you can associate each option with a number. Then, show the display for the options in the dropdown, and when an option is selected, use its attribute as the value to save.

Thank you @mikeloc very helpful!
I am struggling with the final step to get the dropdown selection to use the right value, as there seem to be missing steps in the Documentation for Option Sets.
On the Dropdown, in the Conditional tab, I have…
When ‘this dropdown’ '‘s value’ ‘is’ ‘3 widgets’

There doesn’t seem to be anything I can do from this point because I’m not sure what you mean when you say “use its attribute as the value to save.”

You don’t need conditionals. If you have your option set configured correctly (share some screenshots of the option set, the dropdown, the workflow, and the associated data type), you will be able to reference the selected option’s attribute when you save the dropdown’s value.

I was just following the steps for Option Sets in the documentation and it shows to use Conditionals in the dropdown.

So, I need to use a workflow? I am not following you at all because I’m using the Documentation as a guide and steered me in another direction.

This is why I originally asked for a step-by-step because this is a very specific, generic use case that I feel like a lot of people could benefit from using in the future, so we should put the information on how to do this here :slight_smile:

I’ve solved this with the help of GPT-4

Option Set
Attributes:
number of widgets (number)

Options:
3 Widgets
10 Widgets
20 Widgets

Select ‘modify attributes’ next to each option
Add 3, 10, or 20 to the “number of widgets” box for each option

You can then easily use these values by accessing “Dropdown’s value’s number of widgets”.

Good ol’ GPT-4… not sure how anyone would know how to do anything in Bubble without it!