Forum Academy Marketplace Showcase Pricing Features

Is it possible to create complex states?

I know it’s possible to create a state as a list but is it possible to create a state as an OBJECT (basically key-value pair).
For example, state1 = {first: “John”, last": “Doe”}
I don’t want to create database things, as these states are temporary.

Yes. :+1:
This is complex for us. But for Bubble, is a text like any other :sweat_smile:

Can you please elaborate? How would you create states as Object type?

Sorry, I think I could misunderstood the issue… :expressionless:

Can you explain why are you trying to store complex data as custom states? And how you pretend to get it back? I don’t think you can store OBJECTs as custom state. But if you try to give us a little more info I am sure other members will try to come up with a solution.

I want to create an object state, let’s call it state1.
And I want to dynamically add key-value pairs to state1.
For example, I have list of questions in the database. When user gives response to each question, each of the key-value pair of state1 will be the question’s unique ID and response (uniqueid: text response)

In regular programming world, something like this: state1= {questions[0].uniqueid: response, questions[1].uniqueid: response}

Better of thinking might be: how do I create a temporary thing, without creating a datatype in the database.

Custom states - you can store lists - and that’s it. Beyond that, you have to use text structures to mock up multi-dimensional data structures (think JSON) or use multiple lists.

The way I do key-value pairs is to effectively make them arrays. With custom states have 2 lists, a list of keys, and a list of values, and then find the position of the key, then get the value from the position in the other list.

If anyone had an easier way I’d love to know. :slight_smile:

2 Likes

With a plugin

You can create and work with data types.

You could create an element that uses inputs to output your complex structure and manipulate it from there on like any other bubble object.

🪄 :boom: :exploding_head:

Or just us plain old javascript … then use whatever funky data structure you want … hmmm maybe I should do that - duh! Yeah - don’t do it the way I do it!

2 Likes

You can also add the plugins Json and BrowserStorage and use the browser buffer (json format).

3 Likes

@JohnMark @jared.gibb :+1: :+1: :+1: Thanks for the tip - it will tidy up something messy that I’ve got - I have two Bubble apps - one effectively stores the data - the other API fetches the data from the other - and to make it performant I pre-fetch in the background the API data and store in custom states … this will greatly simplify it - cheers :blush: :blush: :blush:

3 Likes