Skip to main content
Version: v3+

CHECKBOX_GROUP

Supported from API_LEVEL 2.0. Please refer to API_LEVEL for API compatibility.

check_group_sample

Used to select multiple options from a set of choices. Each option needs to be created using STATE_BUTTON.

Create UI Widget

import { createWidget, widget } from '@zos/ui'

const checkGroup = createWidget(widget.CHECKBOX_GROUP, checkboxGroupParam)
const stateButton = createWidget(widget.STATE_BUTTON, stateButtonParam)

Types

checkboxGroupParam: object

PropertiesDescriptionRequiredTypeAPI_LEVEL
xThe x-coordinate of the widgetYESnumber2.0
yThe y-coordinate of the widgetYESnumber2.0
wThe width of the widgetYESnumber2.0
hThe height of the widgetYESnumber2.0
select_srcImage displayed when selectedYESstring2.0
unselect_srcImage displayed when unselectedYESstring2.0
check_funcCallback when button state changesNOCheckFunc2.0
use_colorWhether to display widget using colorsNOboolean4.0

CheckFunc: function

(checkboxGroup: CheckboxGroup, index: number, checked: boolean) => void
ParametersDescriptionType
checkboxGroupThe checkboxGroup instanceCheckboxGroup
indexIndex of the optionnumber
checkedWhether selectedboolean

StateButton: object

PropertiesDescriptionRequiredTypeAPI_LEVEL
xThe x-coordinate relative to radioGroupYESnumber2.0
yThe y-coordinate relative to radioGroupYESnumber2.0
wThe width of the widgetYESnumber2.0
hThe height of the widgetYESnumber2.0
select_colorColor when selectedNOnumber4.0
unselect_colorColor when unselectedNOnumber4.0
fill_widthButton color display area widthNOnumber4.0
fill_heightButton color display area heightNOnumber4.0

Prop Properties

PropertiesSupports get/setTypeNotes
prop.INITsetobjectInitialize the widget and set default selected item
prop.CHECKEDset/getobjectSet/get selected sub-widget state, returns boolean type when getting
prop.UNCHECKEDsetobjectSet sub-widget to unselected state
caution

The widget must be initialized once with prop.INIT to render the view. Currently, initialization only supports single option parameter passing. To initialize multiple options, use prop.CHECKED to set them.

Property Access Support List

CHECKBOX_GROUP

PropertysetPropertygetPropertysettergetter
xYYYY
yYYYY
wYYYY
hYYYY
select_srcNNNN
unselect_srcNNNN
check_funcNNNN
use_colorNNNN

STATE_BUTTON

PropertysetPropertygetPropertysettergetter
xYYYY
yYYYY
wYYYY
hYYYY
select_colorNNNN
unselect_colorNNNN
fill_widthNNNN
fill_heightNNNN

Code Example

tip

Please refer to Design Resources for the image resources in the code example

import { createWidget, widget, prop } from '@zos/ui'

Page({
build() {
const checkbox_group = createWidget(widget.CHECKBOX_GROUP, {
x: 0,
y: 0,
w: 480,
h: 64,
select_src: 'selected.png',
unselect_src: 'unselected.png',
check_func: (group, index, checked) => {
console.log('index', index)
console.log('checked', checked)
}
})

const button1 = checkbox_group.createWidget(widget.STATE_BUTTON, {
x: 40,
y: 200,
w: 64,
h: 64
})
const button2 = checkbox_group.createWidget(widget.STATE_BUTTON, {
x: 190,
y: 200,
w: 64,
h: 64
})
const button3 = checkbox_group.createWidget(widget.STATE_BUTTON, {
x: 340,
y: 200,
w: 64,
h: 64
})

checkbox_group.setProperty(prop.INIT, button2)
checkbox_group.setProperty(prop.CHECKED, button3)
}
})