Cannot Figure out How to Store Local Changes

Hi there,

I’m getting quite perplexed at how to do something that I thought would be quite simple. I have a form-type UI in my app that allows a user to create a Thing (lets call it “A”). As part of creating an A, the user also specifies a number of other Things (“B”), which are stored on a list as a field of A. The number of B’s for each A could be any number, so it embodies a typical 1 to many relationship.

The flow I want looks something like this:

  1. User clicks “Create A”
  2. User fills out basic information about A
  3. User fills out information for each B in A, then clicks “add”, which appends the B to a temporary list
  4. User clicks “Create”. The A and all Bs are created at once

My problem is with step 3. I have a repeating group set up to handle already inputted Bs, and I’ve set the data type of the repeating group to B. However, when the user inputs the information for the new B, I can’t figure out a way to store that B in the repeating group without appending it to the database. I don’t want to append the Bs to the database as the user inputs them, because the user could leave the form before actually creating the A, which would create orphan Bs. Also, it seems unnecessary to have a call for every B added, especially if there are many of them.

So I’m sort of stuck. In a typical web programming stack, I’d just create an array in the browser to hold the Bs, and then submit them all at once. If the user happens to leave the page during it, I don’t really care about preserving them. But I can’t seem to find a way to do this with bubble?

1 Like

Hi austin3.

Have you tried custom states?

In your step 3, when you click the Add button you can add the B created to a custom state type text or custom state type list of texts. That way they are not Bs but just what someone filled into the input.
Or you can create a list of Bs and save it in the state, and have an API workflow that deletes all Bs with no As later.

Let me know if you want further help in a pm.
best regards
Julius

Unfortunately the Bs that people are filling out are items consisting of multiple fields, including multiple text inputs and an image upload. I tried having custom states for each of them and using the index of a repeating group to obtain them, but I ran into a couple issues. First, the indexes were off if one of the optional fields wasn’t supplied. Second, lists don’t allow duplicate values for some reason, and there is no way to disable that feature (this baffles me, to be honest).

I ended up using a structure similar to your second suggestion simply because I could not find another way to do it. Unfortunately, since things cannot be stored directly in custom states, I still ended up having to upload Bs and reference them from state. To be honest this was rather annoying and frustrating. Coming from a perspective of a web programmer, it seems a given that these features should exist.

If you or anyone else has a workaround that would accomplish this, feel free to let me know.

Hi there,

I gave it another thought. If you do not care about loosing the data upon page close/refresh.

Why don’t you do it like this (little hacky) assuming you have a limit on the number of B’s (here 10):

  1. Create 10 Groups with all relevant data inputs for a B

  2. Display first of those Groups (User fills this one out)

  3. If the user wants to add another B, show the next Group on click of a button, let the user Input everything for the 2nd B

  4. Repeat 3. as often as applicable (max. 10)

  5. If the user hits submit you can run 1 workflow with all the actions

    5.1 Add 1 action for creating your A

    5.2 Add 10 actions based on conditions of being visible for each group the user might have filled out

(Of course you could gain a little efficiency through incrementing a new custom state called e.g. “Number of B’s” each time a new Group is shown (decrement if hidden) through the Button click in 3. –> Then the conditions in 5.2 would not be “if visible” but e.g. for Group1: 1<=“Number of B’s”; And you would decrement the states number after each step; Of course from highest to lowest, so your first step would be the 10th Group)

Hope this offers a cleaner solution instead of setting endless states.

Thanks for the idea. If I’m willing to deal with the limit, this will give me the desired functionality. From more research during my time working on my app, it seems like a lot of Bubble is designed around the database, and having local objects is just simply not supported. Thanks for the help, and I’m hoping the team sees this and considers supporting it in the future.

1 Like

Yeah, but if there’s an unintentional network disruption or page refresh, the information already input but not saved to the DB could be lost. Depending on how much info has been entered, that could be quite frustrating for the user.

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