Toggle Yes/No Custom State

@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.

40 Likes

Nice find!

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 :slight_smile:

I wished people used more often the Mark as Solution feature for Discouse :slight_smile:

1 Like

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”

3 Likes

Well, the original question is several months old and the OP probably isn’t paying attention to this thread any longer? :thinking:

(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.)

3 Likes

Yeah, bubble is some times very confusing for my developer alter ego :slight_smile:

1 Like

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…

1 Like

It really seams pretty simple, but I didn’t though about this before I read you.

Thank 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.

1 Like

Well done.

NEW SOLUTION
It’s been awhile this post is here. But maybe someone will find this useful. I found a much cleaner way to do it. It uses two state values. One is your yes/no, one is a number type. It goes like this:
Initial state value: yes and 1
Workflow:
Action 1
Set No if value is yes and if number is 1
Set number to 0
Action 2
Set Yes if value is no and if number is 1
Set number to 0
Action 3
Set number to 1

When one of the events is activated it sets the number to 0 blocking the next action. It’s like using a ‘block’ Uno card on the next player.

I hope this will help someone :slight_smile:

2 Likes

worked like a charm!
Cheers mate

1 Like

OMFG!!! You save me from a 2 days headache! Thanks!!!

Just thought I’d share the solution in this thread:

by @J805

It’s a one-liner that uses “boolean algebra” to create an inverse function.

You can check out the full explanation on the linked thread/post.

image

Cheers and thank you to J805 for the solution

1 Like

Happy to help. :blush:

Damnit I wish I knew that, I made a form and it had 40 yes/no checkboxes so 80 workflows :angry:

1 Like

Not sure why this person shared this info AGAIN in this old thread as I shared it in earlier replies twice, @tylerboodman.

(Also, don’t feel bad about not having been able to figure this out. I literally tore my hair out for hours when I first started using Bubble. While I’m sure someone out there knew how to do it, the first mention of the correct method I’ve ever found is my own post here - way back in April of ‘18…

WTF is there no Boolean "NOT" Operator!?!?!? - #4 by keith )

2 Likes

Thanks @J805 for finding this solution!

@keith :smirk:

2 Likes

Nice approach