Dropdown Category Selection Writing to DB

I made a quick video that walks you through my challenge. :point_up_2: I love loom for this :sweat_smile:

Basically, I’ve spent days researching before coming here to ask for help, I love solving challenges but this one I can’t nail.

Building off of Bubble’s training on “Recipe Sharing Website”

When making a new recipe, I want to allow User to add tags from a dropdown so later another User can filter the results. I’ve added the multiselect dropdown pluging. While designing, I want the User to be able to add a new tag if it’s not already in Data Types. So, I’m choosing “Text” in the “Type of Choices” Field.

This means I have to have 2 Data Types. 1 for “Recipes” and 1 for “Tags”

The recipe is what stores the info to be shown on the page.
The tags is what stores in the backend to later show in the dropdown for future recipe creation (ingredients, type of diet like vegan or gluten free, etc).

Now, in the workflow: I’m filtering the dropdown selections so what is written to the database is only what has not already been submitted before.

However, when there are multiple items (the user can add up to 3 tags) being written to the DB, it adds multiple items using a comma “,”
So, when a new user goes to submit a recipe, they see in the dropdown 2 items separated by a comma. I just want 2 different entries added to the Tags DB.

Very grateful for any and all help.

FYI - I’ve played with “adding a custom state” but it still writes with a comma to the DB :man_shrugging:

1 Like

Hi, welcome to the forum…

Firstly, just to check I understand what you’re trying to achieve…

What you’re trying to do is have a separate database entry for each tag (regardless of whether it’s a type or ingredient etc.) So 1 database entry, per tag.

In other words, if a user adds an ingredient tag of ‘tomatoes’ you want a new database entry for ‘Category DB’ to be created with the ingredient ‘tomatoes’ (assuming one doesn’t already exist).

If a user enters 3 new tags (that don’t already exist in the DB) e.g. ‘ham’ ‘cheese’ ‘eggs’, the you want 3 new, separate database entries to be added to the database.

Correct?

If that is the case then you’re on the right track, there’s just a couple of things you need to do differently, so I’ll try to explain as best I can.

Firstly, there’s no need to have the fields on the Category DB type as lists (i.e. list of texts for Main Ingredients DB etc.)

So I’d suggest changing those to single item fields (it wont’ really matter if you leave them as lists, but might just be confusing in the long run).

Secondly (here’s the main place you’re going wrong at the moment), instead of creating a single new Category DB item, with a list of all the new tags, you need to create a new category item for each new tag on the list.

Currently, you’re using the ‘create a new thing’ workflow action, which can only be used to create a singe entry in the database.

So you’re creating a new ‘Category DB’ entry, and adding a list of all the newly entered tags to that single item - which is why you’re getting one entry in the DB with all the ingredients in a single field (as a list).

In order to create a separate entry in the database for each new tag you’ll need to set up a backend workflow to create a new entry, and then schedule that backend workflow to run on a list in your browser workflow, with the list to run on being the list of new tags.

So, based on your current setup, create a backend workflow, with parameters for ‘ingredient’, ‘type’, and ‘time’, all of type ‘text’, and set to ‘optional’ - so you can pass through the ‘text’ to the backend workflow from your workflow in the browser.

This backend workflow just needs one action - to create a new ‘Category DB’ entry, with each of the 3 fields you’re sending to the workflow set to those values.

Then, in your browser workflow, when the button is clicked, schedule the backend workflow for the current date/time, to run on the list of texts from the dropdown (you’ll need to filter the list to only run on entries that don’t already exist).

Set the fields to send to the backend workflow to be ‘this text’.

(you’ll need to create a separate action for ‘ingredients’ ‘type’ ‘time’ to run conditionally - and just send ‘this text’ for the specific field in question, leave the other 2 blank).

The backend workflow will run on the entries from the dropdown that don’t already exist (i.e. those which have been typed in by the user), and will create a new database entry for each new tag.

1 Like

Do you store value into a list field? Can you share screenshot of your workflow?

Thank you very much for taking the time to write out a solution - very nice of you, @adamhholmes :pray:

Yes - you nailed it, that is what I’m struggling with - adding 1 item to the DB at a time.

I’ve edited my Data Types so they’re no longer lists, but single items.

however, I could not understand this :point_down: part :sweat_smile:

You can only create a single item at a time in a workflow action (there is no ‘create a list of things’ action) in a browser workflow, and you can’t run any kind of looping or recursive workflows client side (without plugins).

So you basically have 3 options…

As you’re limiting the list of new tags to a maximum of 3 items, you could do this in your workflow using 3 separate ‘create a new thing’ actions, to run on each of the 3 tags in the list (only if they don’t already exist and only if they’re not empty).

For example -
action 1 - create a new ‘Category DB’ entry that relates to the first item in the list (if there is one).
action 2 - create a new ‘Category DB’ entry that relates to the second item in the list (if there is one).
action 3 - create a new ‘Category DB’ entry that relates to the third item in the list (if there is one).

Create the new entries on the backend (as outlined in my previous reply).

So create a workflow in your ‘backend workflows’ editor page, that creates a single Category DB entry (use the create a new thing action).

Then schedule that workflow to run on a list - that list being the newly added tags (the ones that have been typed by the user, which don’t already exist).

If you’re not sure how to create and run backend workflows, they can take a bit of time to understand, so read the Bubble manual and check through the forum - there are plenty of discussions and examples you can learn from.

(note, you can’t run backend workflows on a free plan).

The 3rd option is to use the ‘List Shifter’ plugin, which (among other things) lets you run a workflow on each item of a given list right in the browser.

I haven’t got much experience with this plugin personally but, having just tried it out, it’s probably the best, and simplest, of the 3 options for you use case here, so I’d recommend checking it out (it’s free).

Then you can use the ‘create a new thing’ action to run for each new tag, and set up the ‘list shifter’ plugin to iterate on the list of new tags.

It’s fairly simple to set up, so I’d recommend checking it out.

1 Like

@adamhholmes - I can’t explain how much I appreciate your help, thank you! But, it’s still not working :unamused:

I’m trying Option 1 because I don’t have a paid plan (yet), so Option 2 I can’t embrace, and Option 3 pretty much calls for the same action as Option 1 - but with the added use of a plug in. Either way, I’’ have to “create a new thing” action to run each new tag - so, I tried #1 and it’s still not working

It is skipping over the second tag being entered into the dropdown :woman_shrugging: … crazy… No idea how something so theoretically simple should be so complicated.

would be grateful for other ideas or wo

I think you need to get rid of the filter on the field value (I don’t see the logic of applying a filter there) - I’m pretty sure that’s why it’s not working. Actually, looking at your database pic it looks like the entry has been created, it just hasn’t added any data to the Main Ingredient DB field, as you’ve filtered it to return an empty result.

You just want to set the Main Ingredient DB value to dropdown's value; item# 2, but only run the action that when an entry doesn’t already exist with that same value.

So add an ‘only when’ condition to the action: do a search for Category DBs with a constraint to match the Main Ingredient DB value to the value of the input’s item#2, and only run the action when the ‘count’ of those returned results is 0.

That should work fine (it works perfectly in a quick test app I made with the same setup).

1 Like

I didn’t use @adamhholmes ’ fix because the load time for creating the recipe was pretty long. Adam, I’m VERY grateful for your contribution, you’re obviously way more experienced than I am, and I look forward to learning and growing with you here - let’s keep at it!

The fix I finally got around to was the following workflow:
- When dropdown entry value’s change (only when DB’s size is less than dropdown’s entry’s size)
01
→ Set state w/filter
02
Add to DB
03

www.loom.com/share/ac3552dd163e4d5b8ea1f23887a82a21

2 Likes