Multiple Choice
WdCheckboxList
Applicable Scenarios
Tiled options on the page allow users to make multiple selections.
Basic Capabilities Description
Bind an "enum" type field. After the form container is bound to a data model, the enum-multi-select in the model will be automatically rendered as a multi-select component, allowing users to select multiple data items. Configurable default selected values (input option values, not option names when configuring) and component size (effective on PC, not effective on mobile).
Supports personalized configuration of titles, including title content, alignment, line break behavior (when enabled, titles exceeding one line wrap; when disabled, titles exceeding one line truncate with ellipsis), title position, width, and title tooltip.
- Supports personalized configuration of options, including tooltips below options, layout direction, and whether to display underlines on mobile devices.
Note:
The layout direction of options in the multi-select component supports both horizontal and vertical arrangements, defaulting to vertical. When horizontal is selected, it automatically wraps based on option length.
- The default selected values of the multi-select component support configuring multiple default option values.
- If the component is within a form container, its size, title alignment, position, line wrapping, and width will inherit the form container's property configuration by default.
To learn more about usage scenarios for form components, refer to the Form Common Scenarios Practice Guide.
Extended Scenarios Description
Generating Dynamic Option Lists via Query
Using class data as an example, configure a dynamic option list for the component.
Create a class data model and add a class name field within it.
In the Data Management Backend, enter sample class values in this model (note the data environment in the top-left corner; trial data is only available in editor development preview and trial applications; for production applications, enter production data in advance).
Click the '+' in the code area at the bottom left of the editor to create a new WeDa data table query. After completing the following configurations, click the save button in the top right corner.
Data table: Select the class model created earlier
Triggering Method: Automatically execute when input parameters change (executes automatically once on page load to query relevant data)
Filter conditions, Sorting method: Can be configured as needed or left blank
Click the "fx" data binding mode button on the right side of the component option property to open the expression input.
$w.query1.data?.records?.map((item) => {
return {
value: item._id, // Use the data identifier as the option value,
label: item.bjmc, // Use class name as the display label for the option
};
});
- After completing the above configurations, the component's option list can load and display data from the data model, achieving dynamic control of the option list.
Example
Interactive Preview
Different Types of Multi-select
Style API Custom Styles
#wd-page-root .wd-form-item .wd-checkbox-wrap.checkbox1 .wd-checkbox-label {
color: green;
}
#wd-page-root .wd-form-item .wd-checkbox-wrap.checkbox2 .wd-checkbox-label {
color: red;
}
Properties
组件接收的外部传入的属性
属性名 | 属性标识 | 类型 | 说明 |
---|
显示标题 | labelVisible | boolean | 默认值:true |
标题对齐 | labelAlign | string | 表单场景下默认会跟随表单容器的标题对齐配置 |
标题换行 | labelWrap | boolean | 如果标题内容过长关闭时只显示一行、溢出省略;开启时换行展示。表单场景下默认会跟随表单容器的标题换行配置 |
标题位置 | layout | string | 设置标题在表单组件的展示位置,表单场景下默认会跟随表单容器的标题的位置配置 |
标题宽度 | labelWidth | string | 表单场景下默认会跟随表单容器的标题宽度配置 |
标题提示 | labelTips | string | 配置标题的工具提示内容 |
下方提示 | extra | string | 配置后提示内容常显在组件下方 |
选项排列方式 | direction | string | 示例:"vertical" |
移动端显示下划线 | borderedH5 | boolean | 关闭后移动端不显示底部下划线 示例:true |
状态 | status | string | 示例:"edit" |
必填 | required | boolean | 启用后该组件强制必填,值不可为空 示例:false |
必填标识 | requiredFlag | boolean | 启用后,组件若要求必填,则会显示必填星号标记 示例:true |
必填校验提示 | requiredMsg | string | 启用必填,但组件值为空时的提示信息 示例:"该项为必填项" |
绑定字段 | name | string | 表单字段的Key值,用于提交数据时,匹配数据模型字段标识。表单内需保证唯一。 |
标题内容 | label | string | 示例:"标题" |
选项 | range | array | 供用户进行选择的选项列表 示例:[ { "label": "选项1", "value": "1" }, { "label": "选项2", "value": "2" } ] |
选中值 | value | array | 默认选中的选项 示例:[] |
组件尺寸(PC端) | size | string | 多选组件的尺寸宽度,仅在PC端生效 示例:"" |
选项 | tipBlock | string | 示例:"" |
Events
组件暴露的事件,可以监听组件的事件来触发一些外部的动作
事件名 | 事件code | 事件出参 event.detail | 适用情况 | 说明 |
---|
值改变 | change | object
| 兼容三端 | - |
Property API
通过属性 API,可以获取组件内部的状态和属性值,可以通过$w.componentId.propertyName
来访问组件内部的值,如 $w.input1.value
,详请请参考 属性 API
只读属性名 | 属性标识 | 类型 | 说明 |
---|
绑定字段 | name | string | 表单字段的Key值,用于提交数据时,匹配数据模型字段标识。表单内需保证唯一。 |
标题内容 | label | string | |
选中值 | value | array | 默认选中的选项 |
必填 | required | boolean | 启用后该组件强制必填,值不可为空 |
是否展示 | visible | boolean | 组件是否展示 |
是否禁用 | disabled | boolean | 组件是否禁用 |
是否只读 | readOnly | boolean | 组件是否只读 |
选中项名称 | selectedLabel | string | 选中项对应的文本名称 |
选中项 | item | array | 选中项对应的对象 |
Method API
通过方法 API,可以通过程序触发组件内部的方法,比如提交表单,显示弹窗等, 可以通过$w.componentId.methodName
来调用组件方法,如 $w.form1.submit()
方法名 | 方法标识 | 参数 | 方法说明 |
---|
设置值 | setValue | array 值 使用多选组件的设置值方法时,值需要为数组格式。示例:[1,2],其中1和2对应多选组件的选项值
| 通过 $w.id1.setValue("weda") 设置组件值 |
设置显隐 | setVisible | boolean 显示 | 通过 $w.id1.setVisible(false) 设置组件为隐藏 |
设置禁用 | setDisabled | boolean 禁用 | 通过 $w.id1.setDisabled(true) 设置组件为禁用 |
清空值 | clearValue | 通过 $w.id1.clearValue() 清空组件值 | |
设置只读 | setReadOnly | boolean 只读 | 通过 $w.id1.setReadOnly(true) 设置组件为只读 |
触发校验 | handleValidate | 通过 $w.id1.handleValidate() 校验组件值 | |
清除校验 | clearValidate | 通过 $w.id1.clearValidate() 清除组件校验 |
Style API
通过样式 API,可以覆盖组件中内部元素的样式来实现自定义,例如在低代码编辑器中中通过 #wd-page-root .wd-btn
即可为所有的按钮组件编写样式,通过 :scope
可以控制单个组件样式, 详细说明请参考样式 API
名称 | 类名 | 说明和示例 |
---|
根元素 | .wd-checkbox-root | 组件最外层元素
|
H5 端根元素 | .wd-h5-checkbox-root | 可设定 H5 端的根元素样式
|
PC 端根元素 | .wd-pc-checkbox-root | 可设定 PC 端的根元素样式
|
小程序端根元素 | .wd-mp-checkbox-root | 可设定小程序端的根元素样式
|
组件标题样式 | .wd-checkbox-root .wd-form-item-wrap__label | 组件标题元素
|
表单控件根节点样式 | .wd-checkbox-root .wd-form-item-wrap__control | 设置表单控件根元素样式
|
多选控件组根节点样式 | .wd-checkbox-root .wd-checkbox-group | 多选控件组根节点样式
|
多选控件单项根节点样式 | .wd-checkbox-root .wd-checkbox-wrap | 多选控件单项根节点样式
|
编辑态-选项样式 | .wd-checkbox-root .wd-checkbox-label | 编辑态-选项样式
|
编辑态-按钮选中样式 | .wd-checkbox-root .is-checked .wd-checkbox-inner::after | 编辑态-按钮选中样式
|
编辑态-按钮未选中样式 | .wd-checkbox-root .wd-checkbox-inner::after | 编辑态-按钮未选中样式
|
编辑态-按钮背景颜色 | .wd-checkbox-root .wd-checkbox-inner | 编辑态-按钮背景颜色
|
编辑态-校验信息 | .wd-checkbox-root .wd-g-text-error | 设置组件校验信息样式
|
提示文字 | .wd-checkbox-root .wd-form-item__help-text | 设置组件提示文字样式
|
禁用态-选项样式 | .wd-checkbox-root .is-disabled .wd-checkbox-label | 禁用态-选项样式
|
禁用态-按钮选中样式 | .wd-checkbox-root .is-disabled.is-checked .wd-checkbox-inner::after | 禁用态-按钮选中样式
|
禁用态-按钮未选中样式 | .wd-checkbox-root .is-disabled .wd-checkbox-inner::after | 禁用态-按钮未选中样式
|
禁用态-按钮背景颜色 | .wd-checkbox-root .is-disabled .wd-checkbox-inner | 禁用态-按钮背景颜色
|
只读态-表单值样式 | .wd-checkbox-root .wd-form-item__readonly-value | 设置组件只读状态
|
Version Changes
- Property changes
- Style changes
- widget api changes