Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Validate that one or more checkbox are ticked.

John_Kordas
Level 2
Level 2

Currently I'm checking if the user has ticked at least one of the checkboxes by using:

if(CheckBox1.rawValue == 0 && CheckBox2.rawValue == 0){
app.alert("Please select one or more checkboxes.");
}

Is there a way to count the number of checkboxes and do a loop. If you have 15 checkboxes the code above gets a bit hard to read.

I've also use the <validate nullTest="error"/> in the xml to flag the checkbox as being required but this is not true. As long as one or more checkboxes are select the user should not be alerted or shown that checkboxes are not selected. Is there a way to highlight the checkboxes?

1 Reply
Varma_LC
Level 6
Level 6

This is what I would do.....

1. Set up a Global Variable under File>>Form Properties>>Variables Tab

     //Variable declared here are always considered string

     Example: GCheckCount and set the initial value 0

2. For each CheckBox I would add the following code under "change" event

if (this.rawValue == 1) {

     GCheckCount.value = "" + GCheckCount.value + 1;

}else {

     GCheckCount.value = "" + GCheckCount.value - 1;

}

3. Also for each CheckBox I would add the following code under "docReady" event to get the initail count

if (this.rawValue == 1) {

     GCheckCount.value = GCheckCount.value + 1;

}

4. When you validate do the following

if (GCheckCount.value == "0") {

     app.alert("Please select one or more checkboxes.");

}