Forum Documentation Showcase Pricing Learn more

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


#1

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:


#2

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!


#3

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…


#4

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.


#5

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


#6

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