Working with Boolean fields in Bubble

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.

  1. Storing the user_active status as a boolean field and marking it as yes for active users and no for inactive users.
  2. 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.

Creating a Boolean field

You can choose to set a default value if you'd like.

💡
The system assigns the default value if you don't change the value when creating a new record.
Default value

Storing the Boolean value in Bubble

You can update the Boolean field in various ways. You can

  1. Use a checkbox and store the value as yes if the checkbox is ticked and vice versa.
  2. 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.

  1. Find the record we want to update.
  2. 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.

An arbitrary value. You can have different methods to find the record you want to update.

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.

  1. Create privacy rules to enable auto-binding
  2. Define the field which auto-binds to the toggle value.

Read the other tutorial to understand auto-binding and create appropriate privacy rules.

Simple guide to learn auto-binding in Bubble
Auto binding is a method of updating the Bubble database without creating or triggering a workflow.

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.

💡
Always set correct privacy rules (unlike the tutorial). Don't ignore the benefits of good privacy rules for data security.

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.

💡
The value will still be stored as yes/no in the database. We're only formatting the value for UI purposes.

Preview - https://nocodeassistant-tutorials.bubbleapps.io/version-test/boolean
Editor - https://bubble.io/page?type=page&name=boolean&id=nocodeassistant-tutorials&tab=tabs-1

3 proven tips to make your Bubble.io app searches faster today
Learn how to solve the problem of a slow app (without upgrading your server). 1. Use privacy rules 2. Reduce nested searches 3. Avoid advanced filters

Contact us today to explore how Bubble can help your business. We would love to chat with you about how we could work together!