Skip to content

[bug]表单校验不支持动态规则配置 #1053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Azraelj opened this issue Mar 1, 2022 · 2 comments
Closed

[bug]表单校验不支持动态规则配置 #1053

Azraelj opened this issue Mar 1, 2022 · 2 comments
Assignees

Comments

@Azraelj
Copy link
Contributor

Azraelj commented Mar 1, 2022

问题描述

form-item组件的rules属性配置为字面量时可以正常工作,配置为变量时只有第一次调用validate方法能正产校验,后续调用返回的valid字段固定为false

最小可复现仓库

请创建最小可复现代码,并上传到你的 GitHub 仓库

预期的行为和实际行为

rules属性配置变量时也能正常进行校验

复现步骤,具体代码

官网示例将字面量修改为变量即可
如:

<nut-form-item :rules="rule"></nut-form-item>
<script setup>
    const rule=[{required: true, message:''}]
</script>

可能的原因:
checkRule方法中使用了Array.shift方法,修改了vnode的props

相关环境信息

  • 操作系统:macOS
  • Node 版本:10.23.0
  • NutUI 版本: 3.1.16
  • Vue 版本:3.2.31
  • 引用方式: NPM
@LiCeline
Copy link

LiCeline commented Mar 8, 2022

<nut-form-item prop="phone" required :rules="rules.phone" > </nut-form-item>
const [, result] = await errorCatch(ruleForm.value.validate())
const { valid, errors }: any = result
第一次一定会校验valid 会为false
但是到了第二次,valid就会true, 校验异常了

@richard1015
Copy link
Contributor

v3.1.18 已发布

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants