Skip to main content

single choice

WdRadioList

Applicable Scenarios

Options are displayed flat on the page, allowing users to make single selections.

Basic Capabilities Description

  1. Single choice can be bound to a text field in the data model. During form submission, the option value of the single choice will be submitted to the data model. The option name and option value for each option can be configured. The default selected value can be configured (when configuring the default selected value, the option value needs to be entered, not the option name). The component size can be selected (effective on desktop, not on mobile).

  2. Supports personalized configuration of titles, including title content, alignment, whether to wrap (when enabled, wraps to the next line if title text exceeds one line; when disabled, truncates with ellipsis if title text exceeds one line), title position, width, and title tooltip.

  1. 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 single choice component supports both horizontal and vertical arrangements, with vertical as the default. When horizontal is selected, options will automatically wrap based on their length.
  • 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.

  1. Create a class data model and add a class name field within it.

  2. 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).

  3. 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.

    1. Data table: Select the class model created earlier

    2. Triggering Method: Automatically execute when input parameters change (executes automatically once on page load to query relevant data)

    3. Filter conditions, Sorting method: Can be configured as needed or left blank

  4. 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
};
});

Making Selection Non-Cancellable via Styles

.wd-radio-wrap.is-checked {
pointer-events: none;
}
  1. 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 Single-select

Style API Custom Styles

#wd-page-root .wd-form-item .wd-radio-wrap.radio1 .wd-radio-label {
color: green;
}
#wd-page-root .wd-form-item .wd-radio-wrap.radio2 .wd-radio-label {
color: red;
}

Properties

External properties received by the component

Property Name
Property Identifier
Type
Description
显示标题labelVisibleboolean

Default value: true

标题对齐labelAlignstring

表单场景下默认会跟随表单容器的标题对齐配置

标题换行labelWrapboolean

如果标题内容过长关闭时只显示一行、溢出省略;开启时换行展示。表单场景下默认会跟随表单容器的标题换行配置

标题位置layoutstring

设置标题在表单组件的展示位置,表单场景下默认会跟随表单容器的标题的位置配置

标题宽度labelWidthstring

您可以输入数值 + px、%等单位,示例:200px

表单场景下默认会跟随表单容器的标题宽度配置

标题提示labelTipsstring

PC/H5端生效

配置标题的工具提示内容

下方提示extrastring

配置后提示内容常显在组件下方

排版方向directionstring

Example: "vertical"

移动端显示下划线borderedH5boolean

关闭后移动端不显示底部下划线

Example: true

状态statusstring

Example: "edit"

必填requiredboolean

启用后该组件强制必填,值不可为空

Example: false

必填标识requiredFlagboolean

启用后,组件若要求必填,则会显示必填星号标记

Example: true

必填校验提示requiredMsgstring

启用必填,但组件值为空时的提示信息

Example: "该项为必填项"

绑定字段namestring

表单字段的Key值,用于提交数据时,匹配数据模型字段标识。表单内需保证唯一。

标题内容labelstring

Example: "标题"

选项rangearray

供用户进行选择的选项列表

Example: [ { "label": "选项1", "value": "1" }, { "label": "选项2", "value": "2" } ]

选中值valuestring

默认选中的选项

Example: ""

组件尺寸(PC)sizestring

单选组件的尺寸宽度,仅在PC端生效

Example: ""

选项tipBlockstring

Example: ""

Events

Events exposed by the component. You can listen to component events to trigger external actions

Event Name
Event Code
Event Output Parameters event.detail
Applicable Scenarios
Description
值改变changeobject
  • value: string

    单选组件选中值

Compatible with all platforms

-

Property API

Through the Property API, you can access the internal state and property values of components. You can access internal values using$w.componentId.propertyName, such as $w.input1.value. For details, please refer to Property API

Read-only Property Name
Property Identifier
Type
Description
绑定字段namestring

表单字段的Key值,用于提交数据时,匹配数据模型字段标识。表单内需保证唯一。

标题内容labelstring
选中值valuestring

默认选中的选项

必填requiredboolean

启用后该组件强制必填,值不可为空

是否展示visibleboolean

组件是否展示

是否禁用disabledboolean

组件是否禁用

是否只读readOnlyboolean

组件是否只读

选中项名称selectedLabelstring

选中项对应的文本名称

选中项itemobject

选中项对应的对象

Method API

Through the Method API, you can programmatically trigger internal methods of components, such as submitting forms, displaying popups, etc. You can call component methods using $w.componentId.methodName, such as $w.form1.submit()

Method Name
Method Identifier
Parameters
Method Description
设置值setValuestring

通过 $w.id1.setValue("weda") 设置组件值

设置显隐setVisibleboolean显示

通过 $w.id1.setVisible(false) 设置组件为隐藏

设置禁用setDisabledboolean禁用

通过 $w.id1.setDisabled(true) 设置组件为禁用

清空值clearValue

通过 $w.id1.clearValue() 清空组件值

设置只读setReadOnlyboolean只读

通过 $w.id1.setReadOnly(true) 设置组件为只读

触发校验handleValidate

通过 $w.id1.handleValidate() 校验组件值

清除校验clearValidate

通过 $w.id1.clearValidate() 清除组件校验

Style API

Through the Style API, you can override the styles of internal elements in components to achieve customization. For example, in the low-code editor, you can write styles for all button components using #wd-page-root .wd-btn, and control individual component styles with :scope. For detailed instructions, please refer toStyle API

Name
Class Name
Description and Examples
根元素.wd-radio-root组件最外层元素
/* :scope refers to the current component element */
/* For details, refer to the Style API documentation */
:scope.wd-radio-root {
  /* Write CSS styles here */
}
H5 端根元素.wd-h5-radio-root可设定 H5 端的根元素样式
/* :scope refers to the current component element */
/* For details, refer to the Style API documentation */
:scope.wd-h5-radio-root {
  /* Write CSS styles here */
}
PC 端根元素.wd-pc-radio-root可设定 PC 端的根元素样式
/* :scope refers to the current component element */
/* For details, refer to the Style API documentation */
:scope.wd-pc-radio-root {
  /* Write CSS styles here */
}
小程序端根元素.wd-mp-radio-root可设定小程序端的根元素样式
/* :scope refers to the current component element */
/* For details, refer to the Style API documentation */
:scope.wd-mp-radio-root {
  /* Write CSS styles here */
}
组件标题样式.wd-radio-root .wd-form-item-wrap__label组件标题元素

:scope .wd-form-item-wrap__label {
  font-size: 20px;
  color: gray;
  padding: 0;
  display: flex;
  align-items: center;
}
表单控件根节点样式.wd-radio-root .wd-form-item-wrap__control设置表单控件根元素样式

:scope .wd-form-item-wrap__control {
  font-size: 20px;
  color: gray;
  padding: 0;
  display: flex;
  align-items: center;
}
单选控件组根节点样式.wd-radio-root .wd-radio-group单选控件组根节点样式

      :scope .wd-radio-group {
        font-size: 20px;
        color: gray;
      }
    
单选控件单项根节点样式.wd-radio-root .wd-radio-wrap单选控件单项根节点样式

      :scope .wd-radio-wrap {
        font-size: 20px;
        color: gray;
      }
    
编辑态-选项样式.wd-radio-root .wd-radio-label编辑态-选项样式

      :scope .wd-radio-label {
        font-size: 20px;
        color: gray;
      }
    
编辑态-按钮选中样式.wd-radio-root .is-checked .wd-radio-inner编辑态-按钮选中样式

      :scope .is-checked .wd-radio-inner {
        background-color: red;
        border-color: red;
      }
      :scope .is-checked .wd-radio-inner::before {
        border-color: red;
      }
    
编辑态-按钮未选中样式.wd-radio-root :not(.is-checked) .wd-radio-inner编辑态-按钮未选中样式

      :scope :not(.is-checked) .wd-radio-inner {
        background-color: gray;
        border-color: gray;
      }
      :scope .wd-radio-inner::before {
        border-color: gray;
      }
    
编辑态-按钮背景颜色.wd-radio-root .wd-radio-inner编辑态-按钮背景颜色

      :scope .wd-radio-inner::before {
        background-color: lightgray;
      }
    
编辑态-校验信息.wd-radio-root .wd-g-text-error设置组件校验信息样式

:scope .wd-g-text-error {
    font-size: 20px;
    color: gray;
  }
提示文字.wd-radio-root .wd-form-item__help-text设置组件提示文字样式

:scope .wd-form-item__help-text {
    font-size: 20px;
    color: gray;
  }
禁用态-选项样式.wd-radio-root .is-disabled .wd-radio-label禁用态-选项样式

      :scope .is-disabled .wd-radio-label {
        font-size: 20px;
        color: gray;
      }
    
禁用态-按钮选中样式.wd-radio-root .is-disabled.is-checked .wd-radio-inner禁用态-按钮选中样式

      :scope .is-disabled.is-checked .wd-radio-inner {
        background-color: red;
        border-color: red;
      }
      :scope .is-disabled.is-checked .wd-radio-inner::before {
        border-color: red;
      }
    
禁用态-按钮未选中样式.wd-radio-root .is-disabled:not(.is-checked) .wd-radio-inner禁用态-按钮未选中样式

      :scope .is-disabled:not(.is-checked) .wd-radio-inner {
        background-color: gray;
        border-color: gray;
      }
      :scope .is-disabled:not(.is-checked) .wd-radio-inner::before {
        border-color: gray;
      }
    
禁用态-按钮背景颜色.wd-radio-root .is-disabled .wd-radio-inner禁用态-按钮背景颜色

      :scope .is-disabled .wd-radio-inner::before {
        background-color: lightgray;
      }
    
只读态-表单值样式.wd-radio-root .wd-form-item__readonly-value设置组件只读状态

:scope .wd-form-item__readonly-value {
    font-size: 20px;
    color: gray;
  }

Learn about Style API

Version Changes

  • Property changes
  • Style changes
  • widget api changes