Would be a big time saver to have an action that toggles a Yes/No Custom State to on/off
Yes would certainly be handy, it could fit nicely within the Workflow > Visual > Toggle. Then when selecting the element to Toggle, if the element has a state assigned to it, a checkbox appears stating if you want to enable toggle the yes/no state…
Agree this would be handy, but to toggle any Boolean (yes/no) just evaluate:
BooleanValue is “no”
This returns “yes” if the thing is “no”. It returns “no” if the thing is “yes”. So, toggle.
(Though I do hate that syntax and would prefer an operator for Booleans like :inverse or :not.)
Yeah I agree it could be a pretty handy tool!
Instead of boolean use a number n with initial state 0 or 1 depending if you want it to start as false or true. Then every time you want it toggled set state n = n + 1
When you want to evaluate the Boolean just use modulo 2 function on n
So condition n mod 2 is ‘1’
The result depending on n will be
n = 0 -> no
n = 1 -> yes
n = 2 -> no
n = 3 -> yes
And so on…
This is you Boolean toggle.
@JonL While your suggestion works, you CAN just toggle the Boolean! See my note a couple of replies above. A Boolean toggle in Bubble is this (posted a couple replies above):
So you Set State > select the custom state that is a yes/no and set it like this:
This flip-flops the state of SomeBoolean from no to yes and vice-versa.
Sorry didn’t read your post! I will look for my Boolean numeric toggles and swap them for yours. Much easier to maintain and to read
I wished people used more often the Mark as Solution feature for Discouse
This has the added advantage of being able to use Conditions much easier as well. For example, if the thing that triggers the toggle is a button, you can indicate its state by modifying the text on the button in the button’s Conditional tab, like:
When SomeBoolean is “no” > Text is “Off”
When SomeBoolean is “yes” > Text is “On”
Well, the original question is several months old and the OP probably isn’t paying attention to this thread any longer?
(The other thing I’d say about this, as I’ve pointed out in other threads on the same subject: I felt like I was going crazy when I couldn’t originally figure out where the “not” operator was in Bubble. Turns out it’s there, it’s just not an operator… You just have to evaluate the state. This is one of those rare Bubble things that would be perplexing to both a beginner and an experienced developer. It’d be much nicer I think if there were also a :not or :inverse or :negate operator on Booleans and it’d feel much more obvious.)
Yeah, bubble is some times very confusing for my developer alter ego
Excellent trick, thanks Keith!!
Thank you so mucho @JonL for this, even though @keith idea works, the modulo idea is, in my understanding, better, because you just need to use only one event to do the toggle, instead with keith’s idea, you would need two events, because if you toggle in an action, then the following action goes back to what we just toggle before, so at the en is a double toggle, so doesn’t work in the same event…
It really seams pretty simple, but I didn’t though about this before I read you.
Very clever solution! Thank you so much!!
@Keith this is a game changer for settings. Thank you!
For others working on their setting pages, this also works to modify database fields that are Yes/No. The example above shows modifications to custom states.