Skip to main content

YIDA duplicate verification of subform values

此案例由宜搭开发者Peng provides

1. Usage scenarios

In scenarios such as order submission and warehousing, you need to reset the subform when the multi-column selection combination is the same. For more information, see the implementation method in this document.

2. Procedure

2.1 form design

1. Create a subform and add the columns you want to use.

Here I add two drop-down options for demonstration

2.2 add custom verification rules

TIP: each subform component participating in combination verification must set a custom verification function. Copy and paste the same code.

1. Select the column component to participate in the combination verification, select custom function in the lower right corner, and click

Button to open the edit box.

2. Paste the following code in the edit box and replaceidListAndtableIdThe value on your form.

function validateRule(value) {
// 要校验的子表单组件ID列表,可以添加多个,用英文逗号隔开
const idList = ['ID1', 'ID2', 'ID3']
// 子表单ID
const tableId = '子表单ID'

const tableData = this.$(tableId).getValue()
const tableValue = tableData.filter(row => {
// 行中有任意一个要校验的选项没有值则跳过校验
for (const v in row) {
if ('' + row[v] === '') {
return false
}
}
return true
}).map(row => {
//当前行要校验的值拼接一个字符串
let str = ''
idList.forEach(id => str += row[id])
return str
})
//利用Set去重
const valueSet = new Set(tableValue)
// console.log(tableValue)
// console.log(valueSet)
//如果长度相等则证明没有重复的
return tableValue.length === valueSet.size
}

3. Effect display

4. Try it online

This doc is generated using machine translation. Any discrepancies or differences created in the translation are not binding and have no legal effect for compliance or enforcement purposes.
Copyright © 2024钉钉(中国)信息技术有限公司和/或其关联公司浙ICP备18037475号-4