Form Container
WdForm
Practical Guide
Practical Guide for Form/Table Component Binding Expression (query)
Implementation Approach for Pagaged or Step-by-Step Form Submission
Modifying Field Default Values in Form Container Update Scenarios
Applicable Scenarios
Quickly implement scenarios for submitting and displaying form data. After binding a data source, components such as single-line inputs, dropdown selections, and submit buttons can be automatically generated based on field types.
Basic Capabilities Description
- Creating, updating, or viewing form data via the Form Container
- Supports binding data sources of data models or APIs types to achieve data interaction between frontend and backend
- Through field properties, you can control the ordering, visibility, and switching of component types for field mapping within internal form components
- For more practical instructions, refer to the Practical Guide for Common Form Scenarios
Extended Scenarios Description
Calculating and Displaying User Input Data in Forms
Example
The following is a complex value calculation scenario
- formArr1: an array where the value of c in each row is the sum of a and b
- formArr2: an array where the value of c in each row is the sum of a and b
- sum1: the accumulated sum of the c values in formArr1
- sum2: the accumulated sum of the c values in formArr2
Configuration Method
As shown, drag the form container and nested components into place, and configure as needed.
The expression for the value of c as the sum of a and b in the nested component is implemented as follows:
Number($w.formArr1.value[$w.index_formArr1].a)*Number($w.formArr1.value[$w.index_formArr1].b)
sum1 is the accumulated sum of the c values in the array formArr1
The expression is implemented as follows:
$w.form1.value?.formArr1?.reduce((sum, v) => sum +Number(v.c) , 0)
sum1+sum2
The expression is implemented as follows:
Number($w.form1.value.sum1)+Number($w.form1.value.sum2)
sum1/sum2
The expression is implemented as follows:
Number($w.form1.value.sum1)/Number($w.form1.value.sum2)
Dynamically Implementing Data Creation, Update, and Viewing Scenarios Using 1 Form Container Component
Example
Bind a variable to the "Form Scenario" property of the form container, and assign different values to the variable to implement creation, update, and view scenarios.
Configuration Method
- Create a variable of type string named sence
- Bind the form container to a required data model to render and generate form components, then bind the "Form Scenario" property of the form container to the sence variable
- In different business scenarios, assign different values to the sence variable to enable the form container to serve different purposes.
- Assign "create" to the form container to set it as the creation scenario for submitting new data.
- Assign "edit" to the form container to set it as the update scenario for editing and updating existing data.
- Assign "read" to the form container to set it as the view scenario for displaying and viewing existing user data.
Binding Expression
Expressions can be static data or variables. You can connect to built-in data tables and external APIs, etc., via Query, and then bind a query in the expression.

Format Requirements for Method Parameters When Data Source Type is APIs (This feature has been deprecated in the latest version)
When the Form Scenario is "creation", configure
- Add a method: Business-required form fields must be flattened at the root node of input parameters. Example:
- Add a method: Business-required form fields must be flattened at the root node of input parameters. Example:
When the Form Scenario is "update", configure
- Query method: Requires form fields to be flattened at the root node of output parameters. Example:
- Update method: Business-required form fields must be flattened at the root node of input parameters. Example:
- Query method: Requires form fields to be flattened at the root node of output parameters. Example:
When the Form Scenario is "view", configure
- Query method: Requires form fields to be flattened at the root node of output parameters. Example:
- Query method: Requires form fields to be flattened at the root node of output parameters. Example:
Property Introduction
组件接收的外部传入的属性
属性名 | 属性标识 | 类型 | 说明 |
---|
表单场景 | formType | string | 默认值:"create" |
数据源 | datasourceType | string | 默认值:"model" |
数据模型 | dataSourceName | string | 示例:"" |
字段管理 | fields | array | |
数据标识(_id) | _id | string | 示例:"" |
表单值 | value | object | 自动填充表单输入数据。每个键值都分配给具有匹配的表单数据键的输入。 |
查询方法 | methodGetItem | string | 示例:"" |
查询入参 | paramGetItem | object | 直接输入对象字面量, 如 {status: 1} 示例:{} |
新增方法 | methodCreate | string | 示例:"" |
更新方法 | methodUpdate | string | 示例:"" |
PC端表单列数 | colNum | string | 默认值:"1" |
PC端组件宽度 | lgWidth | string | 尺寸配置仅对PC端生效 默认值:"hundred" 示例:"md" |
标题位置 | layout | string | 设置当前容器内表单类组件的标题和输入选择区域为左右布局或上下布局 默认值:"horizontal" |
Event Introduction
组件暴露的事件,可以监听组件的事件来触发一些外部的动作
事件名 | 事件code | 事件出参 event.detail | 适用情况 | 说明 |
---|
提交 | submit | 兼容三端 | - | |
校验成功 | validateSuccess | object
| 兼容三端 | - |
校验失败 | validateFail | object
| 兼容三端 | - |
查询为空 | queryEmpty | object
| 兼容三端 | - |
查询成功 | querySuccess | object
| 兼容三端 | - |
查询失败 | queryFail | object
| 兼容三端 | - |
Property API
通过属性 API,可以获取组件内部的状态和属性值,可以通过$w.componentId.propertyName
来访问组件内部的值,如 $w.input1.value
,详请请参考 属性 API
只读属性名 | 属性标识 | 类型 | 说明 |
---|
是否禁用提交 | isDisabledSubmit | boolean | 表单是否禁用提交 |
表单场景 | formType | string | |
数据模型 | dataSourceName | string | |
标题位置 | layout | string | 设置当前容器内表单类组件的标题和输入选择区域为左右布局或上下布局 |
错误信息 | errors | object | 提交的校验错误信息对象 |
数据源初始值 | remoteValue | object | 数据源初始化请求的初始值 |
表单前端值 | value | object | 当前前端表单状态值 |
数据源类型信息 | dataSourceProfile |
| 数据源信息 |
数据源方法提交入参 | submitParams | object | 数据源方法提交入参, 绑定query的时候没有 |
清除校验 | clearValidate | object | 清除校验 |
Method API
通过方法 API,可以通过程序触发组件内部的方法,比如提交表单,显示弹窗等, 可以通过$w.componentId.methodName
来调用组件方法,如 $w.form1.submit()
方法名 | 方法标识 | 参数 | 方法说明 |
---|
设置值 | setValue | object
| 通过 $w.form1.setValue({a:'111'}) 设置组件值 |
提交 | submit | 通过 $w. | |
置空 | clearValue | object
| 通过 $w. |
清空校验 | clearValidate | 通过 $w. | |
校验 | validate | 通过 $w. | |
禁用提交 | disableSubmit | 通过 $w. | |
启用提交 | enableSubmit | 通过 $w. |
Style API
通过样式 API,可以覆盖组件中内部元素的样式来实现自定义,例如在低代码编辑器中中通过 #wd-page-root .wd-btn
即可为所有的按钮组件编写样式,通过 :scope
可以控制单个组件样式, 详细说明请参考样式 API
名称 | 类名 | 说明和示例 |
---|
根元素 | .wd-form | 表单组件根元素
|
PC 端表单根元素 | .wd-pc-form | 可以为 PC 端的表单编写样式
|
H5 端表单根元素 | .wd-h5-form | 可以为 H5 端的表单编写样式
|
小程序端表单根元素 | .wd-mp-form | 可以为小程序端的表单编写样式
|
Frequently Asked Questions
When using data container components, must other components be placed inside them?
The Data Container is the core component for page-data interaction, capable of directly querying and displaying data. On our platform, multiple data container components are available, such as ListView, DataView, WdForm, and WdTable.
The Data Container enables deep integration of data and page components. This greatly simplifies data operation processes. In addition to providing data, the Data Container also supports common page interaction features, such as pagination loading, loading status, and error prompts.
When using data containers, if a component relies on data returned by the data container, it is recommended to place the component inside the data container component. For example, to display an image from a specific field in a data detail, it is better to place the component inside the corresponding data container. This way, the data container can automatically handle loading states, loading failures, etc., without needing to worry about rendering timing.
If you only need to use the data container to obtain data without performing UI interactions, you can directly use the Query function to query data.
How to prevent duplicate form submissions?
On the form submit button, create a Boolean variable with a default value of false
and bind it to the button's disabled property. When the form container's submit event triggers, perform a "variable assignment" to set this variable to true
. Then, in the success branch, call the data source method to submit the data. After successful submission, trigger another "variable assignment" to reset the variable to false
. During submission, when the variable value is true
, the button remains disabled, thus preventing duplicate submissions.
How do you refresh other components when an event is triggered?
When you need to refresh other components upon an event trigger, bind a variable to the target component's property, for example by referencing this variable in a filter parameter expression. Then change the variable's value in the triggering event to update the corresponding target component's content.