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自定义校验 validator value 参数undefined时返回null #2486

Closed
lljj-x opened this issue Feb 21, 2022 · 1 comment
Closed

form自定义校验 validator value 参数undefined时返回null #2486

lljj-x opened this issue Feb 21, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@lljj-x
Copy link

lljj-x commented Feb 21, 2022

TuSimple/naive-ui version (版本)

2.25.2

Vue version (Vue 版本)

3.2.31

Browser and its version (浏览器及其版本)

chrome 98.0.4758.102

System and its version (系统及其版本)

macos 12.1

Node version (Node 版本)

Reappearance link (重现链接)

https://codesandbox.io/s/hungry-silence-qo0xpp?file=/src/Demo.vue

Reappearance steps (重现步骤)

  1. 打开如上链接,当清空age时,会设置age为 undefined。
  2. 清空age
  3. 查看控制台显示 validator value: null,期望还是undefined

Expected results (期望的结果)

期望在 validator callback中value为 undefined 时,不要默认 null

Actual results (实际的结果)

https://github.com/TuSimple/naive-ui/blob/main/src/form/src/FormItem.tsx#L264

如上代码,在使用 lodash 获取 path value的时候这里做了默认null 的操作

Remarks (补充说明)

不确定这里故意默认 null 的原因,会导致实际的表单数据和这里不一致,一些数据校验不符合预期

@github-actions github-actions bot added the untriaged need to sort label Feb 21, 2022
@lljj-x lljj-x changed the title form自定义校验规则 validator value 参数undefined时返回null form自定义校验 validator value 参数undefined时返回null Feb 21, 2022
@07akioni 07akioni added bug Something isn't working and removed untriaged need to sort labels Feb 21, 2022
@07akioni
Copy link
Collaborator

你说的非常有道理,当时应该就是没考虑那么多,写错了

然后主要就是我不知道 lodash 会这么处理,以为是有 key 就会返回 key 的,没有 key 才会 fallback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants