Skip to main content

Single Choice

WdRadioList

Applicable Scenarios

The page displays options in a tiled layout, allowing users to make a single selection.

Basic Capabilities Description

  1. Single selection can be bound to text fields in the data model. When the form is submitted, the selected value of the single selection will be submitted to the data model. Each option's name and value can be configured. The default selected value can be configured (when configuring, enter the option value, not the option name). The component size can be selected (effective on PC, not on mobile).

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

Image 1f8c441408179cfb9ab45a9ad2ad3e72
  1. Supports personalized configuration of options, including the tooltip below options, layout direction, and whether to display underlines on mobile devices.
Image bfe0ce74615f3c85cadf5a90815067d6

Note:

  • The radio component supports both horizontal and vertical layout directions for options, with vertical as the default. When horizontal is selected, options will automatically wrap based on their length.
  • If a component is within a form container, its size, title alignment, position, line wrapping, and width will default to the property configuration of the form container

To learn more about form component usage scenarios, refer to the Form Common Scenario 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 with a class name field.

    Image 32db67c80574f3b6e048f56d1da2d459
  2. In the Data Management Backend, enter sample values for several classes in this model (note the data environment in the top-left corner of the backend: trial data is only available in the editor development preview and trial version applications; for production applications, formal data must be entered in advance)

    Image 495962a306ad3bd0a37615d9e6d63d94
  3. In the code area at the bottom left of the editor, click the '+' to create a new WeDa data table query. After completing the configuration below, click the save button in the top right corner.

    1. Data table: select the previously created class model.

    2. Trigger Method: Select to automatically execute when input parameters change (executes automatically once upon page load to retrieve relevant data)

    3. Filter conditions, sorting methods: Can be configured as needed or left blank Image 2ffdaddd204e574f5e59b08f5d5ac464 Image 187a83afeb2857cf63639ed42334aef7

  4. Click the data binding mode button "fx" on the right of the component options properties to open the expression input.

$w.query1.data.records.map((item) => {
return {
value: value: item._id, // use the data ID as the option value
label: label: item.bjmc, // use the class name as the label displayed for the option
};
});

Achieving Non-Cancellable Selection via Styling

.wd-radio-wrap.is-checked {
pointer-events: none;
}
  1. After completing the above configuration, 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
Display HeadlineslabelVisibleboolean

Default value: true

Title alignmentlabelAlignstring

In the scenario, the form by default follows the title alignment configuration of the form container.

Line break in headinglabelWrapboolean

If the title content is too long when closed, show one line with overflow omitted; when enabled, show with line breaks. In form scenarios, it follows the form container's title line break configuration by default.

Title positionlayoutstring

Set title display position in form component. In the scenario, it follows the title position configuration of the form container by default.

Title widthlabelWidthstring

You can enter a value with units such as px or %, for example: 200px.

In the scenario, the form follows the title width configuration of the form container by default.

Heading NotelabelTipsstring

Take effect on PC/H5

Configure tooltip content for the heading

Prompt.extrastring

Prompt content is displayed below the component after configuration.

Orientationdirectionstring

Example: "vertical"

Display underscore on mobile terminalborderedH5boolean

After closing, the mobile terminal does not show the bottom underline

Example: true

Status.statusstring

Example: "edit"

Requiredrequiredboolean

Enable required for this component, value cannot be empty

Example: false

Required identifierrequiredFlagboolean

Enabled, the component will display a required asterisk tag if mandatory.

Example: true

Required validation noterequiredMsgstring

Enable required, prompting message when component value is empty

Example: "该项为必填项"

Bound fieldnamestring

The Key value of a form field is used to match the field identifier of the data model when submitting data. It must be unique within the form.

Title content.labelstring

Example: "标题"

Optionrangearray

Option List

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

selected valuevaluestring

Default selected option

Example: ""

Component size(PC)sizestring

Single-selection component dimension width, takes effect on PC only

Example: ""

OptiontipBlockstring

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
value changechangeobject
  • value: string

    单选组件选中值

Compatible with all platforms

-

Properties 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
Bound fieldnamestring

The Key value of a form field is used to match the field identifier of the data model when submitting data. It must be unique within the form.

Title content.labelstring
selected valuevaluestring

Default selected option

Requiredrequiredboolean

Enable required for this component, value cannot be empty

Indicates whether to displayvisibleboolean

Whether to display the component

Whether to disabledisabledboolean

Component Disabled

Specify whether it is read-only or not.readOnlyboolean

Whether the component is read-only

Select Item NameselectedLabelstring

Selected Item Text Name

selected itemitemobject

selected item object

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
set valuesetValuestring

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

Show/Hide SettingssetVisibleboolean显示

Set the component to hidden via $w.id1.setVisible(false)

Set DisabledsetDisabledboolean禁用

Set the component to disabled with $w.id1.setDisabled(true)

Clear valueclearValue

Clear the component value with $w.id1.clearValue()

Set as read-onlysetReadOnlyboolean只读

Set the component to read-only via $w.id1.setReadOnly(true)

Trigger validationhandleValidate

Validate the component value via $w.id1.handleValidate()

Clear verificationclearValidate

Clear component validation via $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
root element.wd-radio-rootOutermost component element
/* :scope refers to the current component element */
/* For details, refer to the Style API documentation */
:scope.wd-radio-root {
  /* Write CSS styles here */
}
H5 root element.wd-h5-radio-rootSettable root element style for the H5 side
/* :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-side root element.wd-pc-radio-rootSettable root element style for the PC side
/* :scope refers to the current component element */
/* For details, refer to the Style API documentation */
:scope.wd-pc-radio-root {
  /* Write CSS styles here */
}
Mini program root element.wd-mp-radio-rootSettable root element style for mini program
/* :scope refers to the current component element */
/* For details, refer to the Style API documentation */
:scope.wd-mp-radio-root {
  /* Write CSS styles here */
}
Component title style.wd-radio-root .wd-form-item-wrap__labelComponent title element

:scope .wd-form-item-wrap__label {
  font-size: 20px;
  color: gray;
  padding: 0;
  display: flex;
  align-items: center;
}
form control root node style.wd-radio-root .wd-form-item-wrap__controlSet form control root element style

:scope .wd-form-item-wrap__control {
  font-size: 20px;
  color: gray;
  padding: 0;
  display: flex;
  align-items: center;
}
radio button control group root node style.wd-radio-root .wd-radio-groupradio button control group root node style

      :scope .wd-radio-group {
        font-size: 20px;
        color: gray;
      }
    
radio button control single item root node style.wd-radio-root .wd-radio-wrapradio button control single item root node style

      :scope .wd-radio-wrap {
        font-size: 20px;
        color: gray;
      }
    
Option style in editing status.wd-radio-root .wd-radio-labelOption style in editing status

      :scope .wd-radio-label {
        font-size: 20px;
        color: gray;
      }
    
Button style in editing status (selected).wd-radio-root .is-checked .wd-radio-innerButton style in editing status (selected)

      :scope .is-checked .wd-radio-inner {
        background-color: red;
        border-color: red;
      }
      :scope .is-checked .wd-radio-inner::before {
        border-color: red;
      }
    
Editing status - Unselected button style.wd-radio-root :not(.is-checked) .wd-radio-innerEditing status - Unselected button style

      :scope :not(.is-checked) .wd-radio-inner {
        background-color: gray;
        border-color: gray;
      }
      :scope .wd-radio-inner::before {
        border-color: gray;
      }
    
Editing status - Button background color.wd-radio-root .wd-radio-innerEditing status - Button background color

      :scope .wd-radio-inner::before {
        background-color: lightgray;
      }
    
Editing status - Verification information.wd-radio-root .wd-g-text-errorSet component verification information style

:scope .wd-g-text-error {
    font-size: 20px;
    color: gray;
  }
prompt text.wd-radio-root .wd-form-item__help-textSet the text style of the component prompt

:scope .wd-form-item__help-text {
    font-size: 20px;
    color: gray;
  }
Disabled state - Option style.wd-radio-root .is-disabled .wd-radio-labelDisabled state - Option style

      :scope .is-disabled .wd-radio-label {
        font-size: 20px;
        color: gray;
      }
    
Disabled state - Selected button style.wd-radio-root .is-disabled.is-checked .wd-radio-innerDisabled state - Selected button style

      :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;
      }
    
Disabled state - Unselected button style.wd-radio-root .is-disabled:not(.is-checked) .wd-radio-innerDisabled state - Unselected button style

      :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;
      }
    
Disabled - Button background color.wd-radio-root .is-disabled .wd-radio-innerDisabled - Button background color

      :scope .is-disabled .wd-radio-inner::before {
        background-color: lightgray;
      }
    
read-only status - form value style.wd-radio-root .wd-form-item__readonly-valueSet component read-only status

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

Learn about Style API

Version Changes

  • Property Changes
  • Style Changes
  • widget api Changes