Skip to main content
Version: v3.x

CHECKBOX_GROUP

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

check_group_sample

Used to select a single result among multiple options. Each individual 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)

Type

checkboxGroupParam: object

PropertiesDescriptionRequiredType
xThe x-coordinate of components.YESnumber
yThe y-coordinate of components.YESnumber
wThe width of components.YESnumber
hThe height of components.YESnumber
select_srcThe selected image of the components.YESstring
unselect_srcThe unselected image of the components.YESstring
check_funcCallback when button state changes.NOCheckFunc

CheckFunc: function

(checkboxGroup: CheckboxGroup, index: number, checked: boolean) => void
ParametersDescriptionType
checkboxGroupThe example of radioGroup.CheckboxGroup
indexSubview index for state changesnumber
checkedCheck or notboolean

StateButton

PropertiesRequiredTypeNotes
xYESnumberThe x-coordinate of components. Coordinates relative to checkboxGroup.
yYESnumberThe y-coordinate of components. Coordinates relative to checkboxGroup.
wYESnumberThe width of components.
hYESnumberThe height of components.
caution

The widget must be initialized once with prop.INIT to render the view

Prop Properties

PropertiesSupports get/setTypeNotes
prop.INITsetobjectInitialize the component and set the default checkbox
prop.CHECKEDset/getobject(Returns the bool type when get)Set selected sub-component.Get the selected state of the sub-component.
prop.UNCHECKEDsetobjectSet unchecked sub-component.

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)
}
})