Search.../

selectedIndices

Sets or gets the indices of the selected options.

Description

Setting the selectedIndices property sets the options at each specified index to be a selected option.

To reset the checkbox group to have no option selected, set the selectedIndices property to an empty array, null, or undefined.

Getting the selectedIndices property returns an array of the indices of all selected options. If no value is selected, the selectedIndices property returns an empty array.

Type:

Array<number>Read & Write

Was this helpful?

Get the indices of the selected options

Copy Code
1let selectedIndices = $w("#myCheckboxGroup").selectedIndices; // [0,2]
Select the selected options by indices

Copy Code
1$w("#myCheckboxGroup").selectedIndices = [0,2];
Display a message if no checkboxes are selected

Copy Code
1$w('#myCheckboxGroup').onChange((event) => {
2 if ($w('#myCheckboxGroup').selectedIndices.length === 0) {
3 $w('#messageText').text = 'You must select at least one value';
4 } else {
5 $w('#messageText').text = '';
6 }
7});