Forum Academy Marketplace Showcase Pricing Features

Calculations between inputs

I need this:

to subtract this:

…and I need the answer to be produced into a different text or input box.

I know how to do this on when I have stored the data before the page load. However, this happens after page load - Any suggestions?

1 Like

Hey Daniel :slight_smile: Can you share a link to your app in the editor?

@fayewatson there you go… I have to have this launched asap so any help would be AMAZING

Let me know when you’re done working your magic so I can check it out. :wink:

Ok, I think it’s calculating as it should! I set this up using custom states, so it’s a little bit easier to work with the two different values. I created a new text element below which shows the difference between the values:

The first workflows I set up occur on page load. When the page is loaded, I created a custom state (“Current Lighting Total” type: text, list: no) which holds the value of “Current Lighting 10 year total” and another custom state (“Titan LED Total”, type: Text, List: No) which holds “Titan LED 10 Year Total”.

This way you can easily work with those values by using the dynamic expression, “roi-main’s Current Lighting Total - roi-main’s Titan LED Total”.

Then I set up two other workflows which update the custom state anytime those repeating group values change. For example, if the User visited the page, the page set the state of the two ‘total’ values we created. However, if the prices changed or if an item is removed, we need that to update immediately of course. The ‘Do When Condition is True’ workflows will update the values every time anything is changed (to keep them accurate).

You can also change the dynamic expression within the text element totals from the longer expressions to: roi-main’s Current Lighting Total and roi-main’s Titan LED Total. Then, if you ever need to adjust the equation, you only need to change the equation in the workflow value inputs. Please feel free to let me know if this is what you were looking for or if you have any other questions. :slight_smile:

You’re amazing - THANK YOU!

1 Like

Glad it’s working Daniel!! My pleasure! :blush:

1 Like

Wait a minute… I Made a mistake :frowning:
I for got to add a *12 before the *10 and when I do it now the text figure doest change?




it needs to be *12 (12 months) *10 (10 years)
which I changed according to your same logic but it’s returning the same before the change?

Got it :slight_smile: I’ll look at the workflows - can you change the app from private to public?

*If you changed the equation within the Do When Condition Is True workflows, it also needs to be changed in the custom state value actions (any actions where the custom state’s value is set). To make things easier, you can right-click copy the expression where you changed it, and right-click paste it into the value inputs where the value needs to be replaced.

I made it public… your help is imperative. :slight_smile:

Great - just changed it :slight_smile: My apologies for not being clear - you have to change it within every part of the workflow (the ‘When’ statement, and in the value input when setting a custom state action). You correctly altered the equation in the ‘When this condition is true’ statement in the workflow, but you didn’t change the value within each custom state - so the state was still the original equation without the 12 months factored in. The ‘When this Condition is True’ statements tells Bubble "If the repeating group numbers are changed, and are different from the total values which were saved as ‘custom states’ during the time of page load - please update the custom states to reflect the correct value [every time this happens]’. This way, the correct value is always displayed to the User. In summary, the actions within our workflows which ‘set the custom state’ are what actually change the roi-main’s Current Lighting Total and roi-main’s Titan LED total values here (so it needed to be changed in every workflow below):

Thank You!! Your logic is a wealth of knowledge!

No problem at all! :slight_smile:

Hi Faye, it’s interesting that the values in the custom state don’t automatically get updated. Is this because it’s defined value is the repeating group’s values?

Would the custom state be automatically updated if it did a search instead?

Faye, are you still there? I just copied your logic exactly for another equation on the page and it didn’t work for me… Can you tell me what I did in error?

Hey @mishav! :slight_smile: Curious to know how you would do this? The values in the custom state don’t get updated because they’re set on page load and also not set by clicking any buttons (such as ‘add to cart’). As long as it’s captured on page load, I don’t think the custom state value will update with a search either but I’m 100% sure. An alternative is to place those equations in two hidden inputs, and do the calculation Input A - Input B. What do you think?

*Or, to convert the text elements to inputs, disable them and style them to look like text elements.

Hey Daniel! Sorry for the late reply - If you need any help please feel free to let me know (The app is set to private now)

Hey again Daniel - Sorry for so many posts. I think the easiest and cleanest way to do this is to use the Inputs method instead of customs tates. You would paste each equation into the Initial Content of the Input, Disable the inputs to prevent the User from changing them, and remove the border and shadow styles so they look like plain texts. I’m not sure why I didn’t think to do this sooner! But I think this way will definitely be better so you won’t have to deal with any custom states, and everything will update immediately. My apologies for any confusion. :frowning: Here is a forum example:



*I used a random expression in the forum example, but you would just paste your two equations within the Inputs’ initial content here:


Does it work the same for Text fields, instead of inputs?

Nice work Faye!

1 Like