Forum Academy Marketplace Showcase Pricing Features

How To Make A Custom State (which is a list of things)?

Any input on how I create a custom state which is a list would be greatly appreciated.

Thanks

Element action > set state > select an element to hold the state > create new state > label it, define type, check list

Value = Element’s State :plus item [new thing to add to list]

“Element’s State” is a list value and “:plus item” is the modifier to add a new thing to that existing list.

4 Likes

Example and editor …

https://buildingonbubble.com/block/selectable-list-1470553906464x624549423891611600

1 Like

This is great. Thank you.

Does it ever matter where a state is held? This is where I may not understand fully.

I have been putting a random group somewhere on the page to hold the state in the past but i thought because this was a list it may have to be on a repeating group.

It doesn’t really matter; as you can see, you have all elements that are on the page to choose from. I would say a best practice is to select the element where it makes most sense for you to stay organized and be able to quickly find it down the road as your app gets bigger and potentially other states are being used. At the very least, document your state locations in a notes section.

Elements can hold multiple custom states, so if it’s easier for you to select 1 element to be the dedicated custom state “holder” (like a group like you did or even the page itself), then do that. I’ve done that and it saves you time when having to hunt down where custom states are, but sometimes it also makes sense to select an element that the state is dealing with to begin with.

An example of this would be the tabbed group template. Add it to a test page and study the elements there - you’ll see that the custom state for changing current tab is on the group that contains all the inner groups.

3 Likes

Hi, thanks also for this. Is there a way to remove an item from a list that’s a state variable? (eg :minus or :remove)

Instead of :minus you have a set the list to “everything except this thing”.

So “unique id <> Current Cell’s unique id” os something similar.

Example here.

https://buildingonbubble.com/block/selectable-list-1470553906464x624549423891611600

Thank you Nigel. I will try this.

This worked. Thanks again Nigel.
I have a different question, but is related so adding to this thread:
Is it possible to add multiple items to a list (:plus is for adding one)?
Say I’ve got a list of things that’s a custom state, and I want to add a list of things (same type) to that list of things, is this possible?

Yes, you could use “Set List” and then use :merged with.

Hey Nigel,

are you able to elaborate more or perhaps post a screenshot :slight_smile:

I have tried multiple ways but none seem to work.

I am trying to achieve something similar.

I have created a custom state which is a list of things (Drinks), from a RG of Drinks I want to add the same Drink to the list more than once.

Regards

@NigelG nevermind - according to the docs this is not possible in Bubble

Yeah, if you want duplicates it isn’t going to work with Merge.

How about using drag and drop?

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