Forum Academy Marketplace Showcase Pricing Features

Subtracting a value from Custom State not working on multiple choice Checkbox

Hi, I’m trying to make an item registration/update page and I need multiple choice Checkboxes with limited number of the checks for the user to choose categories (3 categories, for instance.)

  • Checkbox in the repeating group with dynamic text…
    In order to achieve this feature, I have set a checkbox within repeating group, and the text value is set to dynamic and loaded from a DB called “placeholder_ctgry”. On the workflow, I have also set a custom state and if the checkbox is checked, the value will be added to the custom state, I did the same for uncheck/subtracting and so if the user press the [update] or [register] button, all the selected and added values will be saved on the DB.

  • Limiting the number of the checks…
    In order to limit the number of the check, I have used “input disable” in the condition(there is no “input unchecked” to be found so I used this to compromise), so if the value added to the custom state is >2 this input(checkboxes) will be disabled, and for the user to reset the selected values I’ve made [clear] button and this will clear the values in the custom states and enables the checkboxes once again, and these worked flawlessly!

But the problem is on the item update page.

  • Validating the values from previously selected values…
    On the checkbox, I have also set a condition to validate if the values are already set or exist in the existing item so, if the value existed in the current-page-item in the DB and match with the value on the checkbox, I use [preset status “Checked”] and this way when the user loads the item update page, previously chosen categories are shown “checked” on the checkbox.

  • Reloading the previously selected values from DB to custom state on the page…
    However, after I’ve set this condition I’ve noticed that if the validator is validating from the DB, you cannot use the subtract function to subtract the value since the values are sitting on the DB and not on the custom states. (and I don’t want to change the DB directly until user press the [update] button) So, I have made a one time action in the workflow, if the custom states has 0 value, load the values from DB to custom state. Boon! I thought it’s done but no…

I see checkboxes with previously chosen categories indicating “checked” and also see the existed values in the debugger on my test page, but if I uncheck the checkbox it won’t subtract these values and its the same for the adding but they are counted as checked so the “limiting number of the check” function work just fine… (btw, if I click the [Clear] button to clear the custom state, everything works as I wanted, but no luck when the page is loaded and until I hit the [clear].)

Why is this happening? If the value is once stored in the DB from the custom state, the value will be different from the value stored in the custom state directly from the page?

Sorry about my terrible english but I hope you understand what im trying to achieve here and my problem, if you think you can help please please please let me know. I will much appreciate your help and thx 10000 in advance.

Sounds like there is an issue with the one time action to set the custom state value to be the same as what is in the DB only when the custom state value is 0.

If you share the workflow actions as screen shots to help with showing what you have already setup to complement the written description it will make it easier to point out where there may be a problem.

1 Like

It’s you again! boston85719 Thank you very much.

I have actually just solve this problem, the issue was that I was saving text value to the custom state, and Bubble somehow didn’t read the text when its reloaded from the DB. So I have made the custom state to be “Selected Category” = A list of “Placeholder_ctgry” (this is a place holder for the categories on DB) and not a list of “text.”

So indeed, as you said, there was an issue with one time action, and the cause was the value type.

Thank you so much for your concern and the support!

1 Like

I would like to add one more thing to this question in case if someone wants to duplicate and implement this function to their app later.

On this part above, in order to make the checkbox to be checked when there is already a value existed to the item that a customer is updating, you need to validate the value with the DB and because you are using the condition “If there is no value on the custom state, load the value from the DB” on the workflow this will cause a problem every time a user uncheck all the checkboxes, the checkboxes with exiting value from the DB will be checked again automatically…

How do we avoid this? You create another custom state for the initial validation when page is loaded.

So, here is the whole logic.
1, If the page is uploaded, one time action on the workflow gets triggered (when custom state [initial validator] has no value, load the values from the DB to [initial validator] and the second custom state [Selected_checkbox]). You use this [initial validator] ONLY for this purpose, rest will use another custom state.

2, On the Checkbox, if the item has values previously selected (current page item’s category contains current cell’s “value/category” preset status = “Checked”) this will make the previously selected checkboxes to be shown “checked.”

3, Use another custom state to keep the current selected values. Check/Uncheck values will be stored on this custom state. and this way, if the user unchecked all the checkboxes, one time action will not be triggered.

*Limiting the number of the check feature also uses this “another custom state”

Enjoy!