怎么在提交时限制明细控件的行数
场景
补卡场景,通常补卡明细只允许提交一条的,我们就可以用个性化开发 来验证补卡明细内的数据是否符合条件。
<script>
cf.ready(function () {
cf.addEventListener(cf.EVENT_HOOKS.BEFORE_SUBMIT, function (next) {
// 获取补卡明细的值
var detailValue = cf.form.getFieldValue('Dd_0')
// 获取到值后做判断
if (detailValue) {
var widgetValue = detailValue.widgetValue || []
// 明细值大于 1 行
if (widgetValue.length > 1) {
cf.call('toast', {
status: 'warn',
content: '明细只允许提交一行'
})
next(false)
} else if (widgetValue.length === 0) {
cf.call('toast', {
status: 'warn',
content: '明细至少应该有一行'
})
next(false)
} else {
next()
}
} else {
// 在这里写未获取到明细数据时,你的业务代码
// next
// 自己决定要不要让用户提交
// 需要让用户提交就 next()
// 不需要就直接啥也不做
}
})
})
</script>
欢迎关注我的个人公众号「「小枫学幽默」」一起成长,一起分享生活!!