Simple: How do you make a button change a checkbox to checkmark (yes)?

The checkbox is tiny. So I want to make a checkbox checked when the user taps of a different bigger button.

Should be simple, I can’t figure out how? In code “MyCheckbox.Checked=true;” Sorry I said the word “code”.

I like to use icons, custom states, and a conditional for this:

Preview: https://forumapp3.bubbleapps.io/version-test/checkbox_custom?debug_mode=true
Editor: https://bubble.io/page?type=page&name=checkbox_custom&id=forumapp3&tab=tabs-1

2 Likes

I see what you are doing, thanks so much.

So basically custom states is like adding a property to an object?

Then could you assign that custom state to a database field, correct? like this: field = iconCheck’s checked value

Did you declare your “checked” property to be of yes/no type?

Oh, and what is the original state of the checkbox as you haven’t run any workflows yet?

Great questions!

  • A custom state stores a value to an element temporarily, so once the page is refreshed, that state is cleared. It’s a great way of storing a value when you don’t need to save it to the database (ever or if you’re just not ready to yet…)

  • There are built-in states that you already have available to you: hover and pressed, which you may have seen in the conditionals. This is the same type of thing, but we’re custom building a state.

  • Yes, you can save custom state values to the database exactly like you described. Field (yes/no) = iconCheck’s checked

  • I did declare it a yes/no. When you use the “set state” action in a workflow and the state is not yet created on an element, you’ll select “create new” and then label the state and declare type (similar to creating a new field). State values can also be lists.

  • By default a custom state will be empty until you set it to some value, and a yes/no state will be no.

2 Likes

Great answers!

What I find interesting that custom state is kept or created in the container that holds the icon in your case.

The icon is responding to the custom state. So the icon is just a regular square icon without the state and when the state is no. When the custom state’s value is “yes”, then the condition created on the icon element is met. I set it up so that when it is “yes”, the icon changes to a different icon - the same square with a check.

To give the effect of a checkbox being checked and unchecked by the user, I change the state when the icon is clicked.

So, think about it this way. It’s VERY similar to just saving a value in the database. In fact, you could do that for this as well. When icon is clicked and Thing’s field = yes > make a change to a thing > field = no (and another workflow for the reverse). Then the icon’s condition would be “when Thing’s field = yes > change icon”

The reason a custom state is better for this is because you don’t use up workflow counts with them and unless you want to create a bookmarking feature, you really don’t need to save the value every time it is checked or unchecked (i.e. if someone keeps changing their mind). You just want to save the value when you’re ready to save (i.e. person has made up their mind about their selection).

1 Like

Thank you so much, you are a great instructor and consultant.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.