How to store database objects in a custom state and modify them locally without changing the database?

I’m running into an issue with custom states and database objects. I want to retrieve a list of items (data type Item) from the database and store them in a custom state. The idea is that users can modify these items locally but the changes should only be saved when they click a “Save Changes” button.

However, I’ve noticed that as soon as I modify an item in the custom state, it immediately updates the database. This seems to be happening because custom states only store a reference to the original database object instead of creating a true copy.

Is there a way to load database objects into a custom state and modify them locally without affecting the database immediately?

Hey,

What I would do if I were you would be to only change the fields of the item once the button “save” has been clicked. There is no way to change an Item locally.

Let me know if this helps

Julian

There’s no way in Bubble to modify a ‘thing’ independently of its existence in the database.

A ‘Thing’, by definition, is a database object, and any reference to it elsewhere is just that (i.e. a reference to the database object) - so making changes to a Thing ALWAYS updates the database.

If you really need to make changes locally then you’ll have to create a local version of it (using javascript), make change to that (using javascript) and then you can pass that into t backend workflow (as JSON) and update the Thing(s) there based on that.

(there may be some plugins to make that easier)

1 Like

Hi there,

I recommend you looking at both this post:

And this plugin:

The latter would be best but you’ll most likely incorporate concepts from the first post as well.

Everything happening in Customize mode on a recipe in my app is utilizing JSON Things and custom states (click ‘Customize Recipe’):

2 Likes

hi thank you for this message. this looks very interesting. tomorrow i will take a look at it and i will let you know. cheers

2 Likes

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