Forum Documentation Showcase Pricing Learn more

Auto-binding and summing values


#1

Hi everyone,

I am trying to use auto-binding to save numeric values to my database.

My scenarios is:
I have three input fields (one for price, one for quantity and the last one for discount percentage) and they have auto-binding enabled.

Now I would like to add a fourth input which would display the total and save it automatically to my database (E.g. Total = (price* quantity) - (price * quantity/100* discount percentage) ).

Any ideas?

Thank you


#2

Hi there @ljf
Yes, I have an idea… which is not to use autobinding. :frowning:
I played with it for ages and came to the conclusion it has all sorts of problems in real world use. I just avoid it completely.

Sorry to the the bearer of bad news…

Best wishes
Antony.


#3

I would try something like this. Create a custom event to calculate the total from your input values. This can be saved directly to the database in a make changes to a thing action.

Trigger this event when any of the three inputs has their value changed (and all three inputs have values).

Display the total from the database in your fourth input (or you can use a text element).

I agree with @antony though, that autobinding should be avoided where possible.


#4

Hi @antony and @louisadekoya,

Thank you very much for your answer.

The only reason why I have had to use auto-binding up to now is because those inputs are inside a repeating group. I have only one button, underneath the repeating group, which has to save everything to database.

Unfortunately there is no way when clicking this button to use “create a new thing…” and getting the values of the inputs, because they are inside the repeating group.

Am I right, or there is a better way?

Thank you


#5

Hi @ljf… I have moved to putting a save button in each cell of the RG, and having a condition on it which makes it light up if data has changed which needs saving. A bit more work for the user, but much much more reliable in the way Bubble works.


#6

Hi @antony,

Yes using this method is much more reliable but it does not fit my case. I was hoping that there was some workaround.

Thank you


#7

Hi @ljf, I think I might have a solution for that. You can create an input, then this input should not be visible on page load. Initial value of this input should be whatever you want to save, then enable auto binding. This should work.


#8

Hi @vansokip,

I don’t I fully grasp how to accomplish this.
This is the editor to explain better what I need: https://bubble.is/page?type=page&name=index&id=inputboxandrp&tab=tabs-1

Thank you


#9

Hi @ljf, this is what I did, when the value of any of the three inputs change, you run a workflow to create the “total”, this is easily done using the expression, only that this time round you wont have to use the input’s value, because they’re already saved in the database (autobinding).


#10

Hi @vansokip,

Thank you very much for your help. I think this solves my problem.


#11

Hi @antony, could you explain a bit more what you mean by this. I have had great success implementing autobinding for certain functionality but was just wondering if I should be anticipating any sorts of problems that I may not have noticed yet by relying on it.