# Changing quantity without updating database

**URL:** <https://forum.bubble.io/t/changing-quantity-without-updating-database/42887>\
**Category:** Questions\
**Created:** [November 20, 2018, 7:48pm UTC](https://forum.bubble.io/t/changing-quantity-without-updating-database/42887 "2018-11-20T19:48:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nocodeventure](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/nocodeventure/32/247164_2.png) [@nocodeventure](https://forum.bubble.io/u/nocodeventure)\
**Post date:** [November 20, 2018, 7:48pm UTC](https://forum.bubble.io/t/changing-quantity-without-updating-database/42887/1 "2018-11-20T19:48:24Z")

</div>

Dear Bubblers,

I’m really trying to see what would work best for me. I’m trying to update a product quantity after pressing the “+” button without updating the database, i don’t know if that is smart or it’s better to update the database directly.

The reason I would not like to update the database directly after the “+” button is the delay it would cause and only updating the quantity in database after clicking “ADD” would be smarter in my opinion.

**I have set the following:**

Initial content: 1  
APP DATA Product - Quantity = “1”

 ![Screenshot%20(11)](https://us1.discourse-cdn.com/bubble/original/3X/7/3/7315d2e2a621fae17ffc17323e28d20de4b680eb.png)

---

<div class="post-metadata">

**Author:** ![max79268](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/max79268/32/32144_2.png) [@max79268](https://forum.bubble.io/u/max79268)\
**Post date:** [November 20, 2018, 8:44pm UTC](https://forum.bubble.io/t/changing-quantity-without-updating-database/42887/2 "2018-11-20T20:44:37Z")

</div>

you can do it with two states.  
first state captures current count then second state is a buffer that displays your first state current count + 1, i think if you want to be extra fancy you use javascript for how many button presses in what time to change what “+ amount you give per workflow cycle”

I think sliders are probably a bit better if this concern you though, depends on what youre selling,  
if its conventional to buy a lot or more than one, slider is way to go but if its one or two products at a time the delay shouldnt really matter at all.

[https://puu.sh/C52Wf.png](https://puu.sh/C52Wf.png)

---

<div class="post-metadata">

**Author:** ![max79268](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/max79268/32/32144_2.png) [@max79268](https://forum.bubble.io/u/max79268)\
**Post date:** [November 20, 2018, 8:46pm UTC](https://forum.bubble.io/t/changing-quantity-without-updating-database/42887/3 "2018-11-20T20:46:18Z")

</div>

but generally small delays are ok, i think a loading animation is nicer. Maybe your button text has a state to change to “adding”

---

<div class="post-metadata">

**Author:** ![nocodeventure](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/nocodeventure/32/247164_2.png) [@nocodeventure](https://forum.bubble.io/u/nocodeventure)\
**Post date:** [November 21, 2018, 5:30pm UTC](https://forum.bubble.io/t/changing-quantity-without-updating-database/42887/4 "2018-11-21T17:30:47Z")

</div>

It’s a wholesale bulk purchase, so it would be nice to add Javascript to manage the counter. Will look into it and will let you know if I can solve this. Thanks for the advice guys.

You can check the app here

[https://b2bcheckout.bubbleapps.io/version-test/homepage?debug\_mode=true](https://b2bcheckout.bubbleapps.io/version-test/homepage?debug_mode=true)

---

<div class="post-metadata">

**Author:** ![sridharan.s](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/sridharan.s/32/17881_2.png) [@sridharan.s](https://forum.bubble.io/u/sridharan.s)\
**Post date:** [November 21, 2018, 5:36pm UTC](https://forum.bubble.io/t/changing-quantity-without-updating-database/42887/5 "2018-11-21T17:36:35Z")

</div>

Our approach to this type of challenge:

- On page load, load the list of quantities from the database to a custom state.
- Have the elements on the page set to reference the custom state and not the database.
- When a user changes the quantity on the UI, then 1st update the custom state - this way it happens instantly for the user
- In the same workflow, update the database. Note, I like to add a condition to this action so it runs only if the quantity is the same as I’m adding back to the database (so if a user changes it a few times in a row, the database doesn’t get updated with the wrong data at all).

As such, you get the immediate responsiveness of client side interaction while also maintaining an always up-to-date version in the database.
