How to calculate the sum of inputs within a Repeating group?

I’ve been trying to find a solution for days now…
I have a repeating group with a title and an input → only the title is saved in the DB.

I want to calculate the sum of the inputs without saving them to the DB. I’ve tried using states, but i can’t save a value as a state for some reason. :slight_smile:

Here is the editor:
https://bubble.io/page?type=page&name=repeating_group_inputs&id=bug-app&tab=tabs-1

Hi @Bubbler

What you are trying to achieve with this ? Why you don’t want to write those inputs / or call from db?

Explaining the idea behind will be helpful :slight_smile:

Cheers!

Thank you for replying.

I’m allowing the users to pick an item and assign a price to it, so i think that saving each change in the DB will make the app very slow, but looks like i got no choice…

Two methods I can think of.

A. As the input’s value changes, use a workflow to manage a list of prices in a custom state.

Because list operations like :plus item automatically take out duplicates, using a list of numbers isn’t great if the user enters the same price for two or more. So instead, make each item a unique text.

Then outside the RG, the list of unique texts needs to be split back into just the prices for summing.

demo page editor, sum repeating group inputs without saving to database

demo page runtime

image

B. You can use javascript to grab each input’s value and sum them. If you like coding, this method makes sense.

6 Likes

Awesome, i wasn’t aware that i could use JS in bubble, good to know.
Thank you :slight_smile:

Hi,

I was reading this post and I have a similar situation and I would like to know if there is a preview on how to use JS to sum the values of each input in a repeating group.

Thank you

1 Like

Hi Mishave,

quick question - there are 2 element i dont understand.

  1. ListNumberA - what element is this and why is the group is referencing to this?
  2. ExpressionA - what element is this and why this is needed?

Hi Mishav,

At the end the dynamic data don’t show me the 's value option, any idea?

Is it still the same roundabout way that we have if we want to save/sum etc input values of an RG? Or now there is some new method that enables this?

1 Like

@mishav, you are a genius. Thank you so much!