Skip to content
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

form.validateFields可否支持忽略校验的namePath #37535

Open
ILoveChy opened this issue Sep 13, 2022 · 4 comments
Open

form.validateFields可否支持忽略校验的namePath #37535

ILoveChy opened this issue Sep 13, 2022 · 4 comments

Comments

@ILoveChy
Copy link

What problem does this feature solve?

现在有一些奇怪的需求,想要展示出某些必填项,但是点击提交或者某个方法时触发校验忽略那些必填项
希望可以对form.validateFields的第一个参数进行下功能上的优化 或者通过传递第二个参数 实现不校验某些值这个功能

What does the proposed API look like?

https://codesandbox.io/s/ji-ben-shi-yong-antd-4-23-1-forked-n4zf5g?file=/demo.js

  1. form.validateFields可否加个第二个参数,比如(namePath?:namePath[],isIgnore?:boolean)=>Promise;
  • 用作是否对form表单整体校验忽略某个字段的校验
  1. 只传递多层级节点的某个层级或者根节点,而不是完整节点
  • 存在3个子组件name分别为["a","b"],["a","c"],["d","e"]
  • 我只给namePath传[["a"]]或者基于上面的实现传递 [["d"],true]/[["d","e"],true]
  • 则可以只校验a,b和a,c从而忽略d,e字段,
  • 现在好像只能做到[["a","b"],["a","c"]]才可以得到我想要的结果
@suiyun39
Copy link

必填样式可以通过 Form.Item 上的 required 单独控制是否显示, 可以和校验规则脱离开的

@ILoveChy
Copy link
Author

必填样式可以通过 Form.Item 上的 required 单独控制是否显示, 可以和校验规则脱离开的

但是我们奇怪的需求就想,这个item是必填的 只是不在form.validateFields的时候统一校验,要在别的触发时机时候校验,当然我给需要忽略的地方单独再包个Form也可以 但是这样就会存在一些Form之间相互数据传递的不便利性了.

@heronCc
Copy link

heronCc commented Sep 15, 2022

确实,现在这种不是很方便

@kind-hearted
Copy link

考虑使用不同的trigger,你可能要看一下async-validator的文档

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

No branches or pull requests

5 participants