How to automatically check a checkbox connected to dataset

I am trying to add a checkbox element and connect it to a dataset that is a boolean field. As soon as I connect the element to the database and I preview, it will not automatically check the field box with a check mark. Can someone tell me how I can load a page that will have a check mark already in the checkbox field that is connected to a dataset? Assume I do not have any coding knowledge. Meaning if there is a coding requirement I need the whole code and not just parts of it. I want this element automatically checked so when I hit a submit button the boolean field is checked in the database.

Hi Matthew

You can read about the functionality of CheckBoxes here in the API.
Anyway, making the checkbox checked by default is pretty easy; Just go to the checkbox settings and mark the option “checked by default” as shown here:


It might require you to ungroup the checkbox itself from the text box that comes along when you add it to your editor.

Hope it helps!
Best of luck.

Doron. :slight_smile:

Doron, Thank your for your reply. First, yes I have read about the checkboxes in the API, however, the API assumes that I am a coder or have a baseline knowledge of java. There are not enough examples of each of the API elements for a non-coder to easily figure out what the code is doing. Secondly, I am also very familiar with how to set the value by default within Wix on a checkbox element, however, what I am experiencing is that when I connect the checkbox to a database, it no longer defaults to being checked. It will show as being defaulted in the image you attached to your reply, however, it is not checked when I push this out to a live site.

Hi Matthew!

What I would suggest you to do is to add an event to the checkbox (View Properties), ’ onChange ', and set a condition that will update the data of the boolean field in your collection every time the value of the checkbox is changed.
The update should happen by one of two options, either through the dataset (if your component is connected by one) and then you should use the setFieldValue( ) and save( ) methods.
Or simply by update( ) of the database.
For example, using a dataset (“#dataset1”) - it should look something like that:

export function checkbox1_change(event, $w) {
	$w("#dataset1").setFieldValue("BoolTest", $w("#checkbox1").value);
	// "BoolTest" is my example field name for a boolean variable
	$w("#dataset1").save();
}

Hope it helps!
Best of luck.

Doron. :slight_smile:

Very good! it worked!

But how the checkbox can be saved in the database for each user?