In Bubble, the Boolean or yes/no field is a field that has one of two possible values (usually denoted true/false or yes/no).
You can use the Boolean in various cases.
- Storing the user_active status as a boolean field and marking it as yes for active users and no for inactive users.
- Storing the onboarding status of a user and marking it as yes for users who have completed onboarding and no for users who have yet to complete the onboarding.
You can imagine many more use cases.
Creating a Boolean field in Bubble
To create a Boolean field, select the yes / no field type. This will create a new Boolean field.
You can choose to set a default value if you'd like.
Storing the Boolean value in Bubble
You can update the Boolean field in various ways. You can
- Use a checkbox and store the value as yes if the checkbox is ticked and vice versa.
- Use a toggle input and store the value as yes if the Toggle is enabled and vice versa.
Both methods are similar, so for this tutorial, let's create the workflows with a toggle input.
I've placed a toggle button, and I want to store the value in the database. As we'll be creating a new record whenever we press the 'save' button, the workflow will create a new record.
Storing a 'Toggle input's value is checked' is the way to store its value, even though it may initially seem unclear.
Bubble will save the current value of the Toggle value regardless of whether the Toggle is checked or unchecked. It works weirdly, but that is how it operates.
Updating the Boolean value in Bubble
The dynamic expression will remain the same if we want to update an existing Boolean value.
- Find the record we want to update.
- Pass the new value we want to over-write.
For the sake of this tutorial, I have assigned a type of content to the Group Master and have passed a random record to that group. I will use the record in this group and update its 'value' field.
We'll use a new button to update the value. The same expression, 'Toggle input's value is checked', will be used to overwrite the existing value.
Auto-binding the Boolean value in Bubble
Auto-binding is a feature that lets you modify and update a field in your Bubble database without using a workflow. It allows us to reduce the number of workflows in our app and improve the UX for our users.
To auto-bind the boolean field, there are two steps.
- Create privacy rules to enable auto-binding
- Define the field which auto-binds to the toggle value.
Read the other tutorial to understand auto-binding and create appropriate privacy rules.
We'll check the 'Enable auto-binding' checkbox. This will present us with the option to auto-bind to the Toggle.
As our boolean field is called 'value', we'll select this field from the dropdown.
Once we do this, Bubble will prompt us to create privacy rules.
To get around the requirement, we'll create a basic privacy rule.
Once the rule is created, we're all set.
Bubble will automatically fetch the value of this field of the chosen record and set the Toggle as checked if yes and unchecked if no.
And whatever changes we make to the Toggle's value will be automatically updated in the database without any workflows.
Formatting the output of a boolean field
We can format the output of a boolean field in different ways. We can display text based on the value.
For example, if the value of a field stores the verification status as no, we can display the output as "Verification pending" or if it is yes, "Verification completed".
We can use the :formatted as text operator to achieve the result.
Preview - https://nocodeassistant-tutorials.bubbleapps.io/version-test/boolean
Editor - https://bubble.io/page?type=page&name=boolean&id=nocodeassistant-tutorials&tab=tabs-1
Contact us today to explore how Bubble can help your business. We would love to chat with you about how we could work together!
Join the conversation.