Custom State with List of "Types"

I am building an auto service shop “create listing” page. I want to let the vendors create their own options list and set their options’ pricing per option.

The way it supposed to work is:
1.) The “add” button creates a custom state item type that contains “option description” and “pricing”
2.) The repeating group shows the list of custom state item type
3.) When they click submit, the “list of custom state items” will then be converted into actual data by storing it in a data type called listing, as a list of options.

I created a custom state called “temp_options” to store the list of custom state items (step 2). But I am not sure how to do step 1, it seems like you can only add one field to the custom state? If I add a description to one custom state item, and then separately add pricing to another custom state item. How do I connect them together and add them to the temp options?

You set the current value of the state to be state:add item and :remove item (for remove)

1 Like

Hi, I’m having so much trouble with even the most basic example of this! I have

• an input field to add new genres
• an add button
• a custom state on my page called Genre with the state type of Genre and ‘List’ ticked.
• a repeating group to show the list of genres

When I edit workflow of the Add Button I cannot make it go blue (validate)! I am assuming the Value is whatever the user has typed in the Input Genre text field. I’m at the point where the red ‘more’ prompt is making me want to scream! I don’t get the :plus item that many other threads have mentioned.

Hey @emma1

It is likely a type mismatch error. Can you share a screenshot of the message in the “Issues” alert in the top right of the editor?

Edit: you are trying to pass in a single Genre when the state is set to a list of Genres. You need to set the state value to: new_artists Genres : plus item current input’s value

Hey @robhblake, I feel like i’m closer but still no cigar…

Here’s the error message:

You’re correct that a custom state can not have multiple fields - a custom state is just a state name and a value (or list of values).

The value of a custom state can be a ‘thing’ (a datatype entry from your database) but you can’t create a new ‘thing’ in a custom state.

One possible way to do what you’re trying to do is to use 2 separate custom state lists - 1 for the description and 1 for the price - however this is not ideal as the only thing connecting the 2 items is their position in the lists - so if something were to go wrong and an item didn’t save to one of the lists for some reason, the 2 lists wouldn’t match up, all the data would be wrong.

It’s also worth noting that in Bubble custom state lists can not contain duplicate entries. So if, for example, you had 2 options with the same price, only one of those prices would store on the price list, and the 2 lists would be out of alignment making all the data wrong.

A better way to achieve what you’re trying to do is simply to save the data directly to the database.

Have a datatype called ‘Option’ with all the fields it needs (description, price, and probably a listing field), and when a new option is added just create a new ‘option’ in the database.

When the listing is saved, you can (if you want) add those options to the listing on a list field.

If the listing is cancelled or deleted, then just delete the list of options.

Alternatively, you might want to take a look at the ‘ListShifter’ plugin, which gives much more advanced list processing functionality directly in the browser, so you might be able to use it for your use-case to create temporary ‘options’ before saving them to the database.


Your custom state ‘Genre’ is of type ‘Genre’

But your Input Text Genre is (presumably) a text.

The value of the custom state needs to be an actual (existing) Genre from your database.

So if you’re using a text input to find a Genre, you’ll need to search the database for a Genre, where a specified field (a text value) matches the input texts value, and select the first item.

So your custom state value should be:

new_artist’s Genre: plus item
search for Genres: name (for example) = Input Text Genre’s value
:First Item

OH MY GOOOOD! It works @adamhholmes :laughing:
There’s no reason for me to have a data type called Genre because I just want people to add whatever genre they feel is appropriate! I’ve changed it to type = text now and it works fine
I’m sure I’m going to run into issues with saving these genres next, but that’s another battle.

1 Like


That’s great…

Although it might actually be worth considering having a datatype for Genre - especially if you’re intending to allow your users to search for items based on their Genre, or you need to sort or analyse data in some other way based on the Genre.

If you just use ‘text’ for Genre, and especially if you’re allowing users to enter that text themselves, then you may end up with many different ‘texts’ for the same genre.

For example:

psychological thriller
Psychological thriller
Psychological Thriller
psychological Thriller

These would all be considered different values, and therefore different genres (not to mention any spelling mistakes or typos), so if you or your users are searching or sorting by Genre, your results could end up being inaccurate.

Whereas if you have a Genre datatype you can match them all up to the same Genre.

You can still allow users to create a new Genre if it doesn’t already exist, and then add that to the database so other users can use it in the future.

If you’re not planning to do anything with the ‘Genre’ field (no searching or sorting for example), then leaving it as a text field is fine.

So, like most things, it really depends on what you’re using it for as to what will be the best way to do things in your app.

oh man, you’re right @adamhholmes - so instead of a text input field, do you think I should have a search input? Really appreciate your time on this!


A search box would be ideal for this.

Then, as your user types into the box, they’ll see all the existing ‘Genres’ that match what they’re typing, so then can select one from the list.

You can also choose to allow them type something that’s not on the list - so if they want to add a Genre that you don’t yet have in your database they can.

You’d have to have a workflow that creates a new ‘Genre’ database entry if what they type doesn’t match an existing Genre, then add that Genre to the item.

I’m really close, @adamhholmes, but I want to cry. So i’ve got

• search box
• I’ve ticked “Allow entries not in list”
• A data type called Genre, with the search input searching Dynamic Choices of Genre. I’ve added a few to get me started.
• Here’s my custom state expression:

Which is nice and blue! But when I try to add a genre that isn’t in the list, nothing is added. I need a drink!

If your custom state type is ‘Genre’, then its value must be an existing Genre from the database.

So if you’re allowing users to add new Genres that aren’t in the database, then you’ll first have to create a new ‘Genre’ entry, then add that to the value of the custom state list.

So, when the button is clicked run the following workflow steps:

  1. Create a new ‘Genre’ (only when searchbox’s typed text is not empty) - and set the Genre Name to the searchbox’s typed text

  2. Set State of new_artist’s Genre (only when searchbox’s typed text is not empty) to new_artist's Genre: plus item: result of step 1

  3. Set State of new_artist’s Genre (only when searchbox’s value is not empty) to new_artist's Genre: plus item: searchbox's value

Then you can reset the input.

@adamhholmes, I don’t know why there’s no Buy a Beer button on this platform, because you’d be 4 pints up now. It works! Thank you so much!

1 Like

Thank you @richard10 and @adamhholmes for the answers. You are right, adam, I could not make that work. The solution that I can come up with is to store “description” and “pricing” into a data type called “options”. Then add multiple “options” into a custom state list. Then I showed the custom state in the repeating group.

But I think your suggestions work better. I changed it to save directly to the database now. It works like a charm now. Thank you everyone again!


This topic was automatically closed after 70 days. New replies are no longer allowed.