alibaba-fusion / next

🦍 A configurable component library for web built on React.
https://fusion.design
MIT License
4.58k stars 584 forks source link

[Field]Field 表单校验的BUG #1039

Closed huarse closed 5 years ago

huarse commented 5 years ago

Component

Field

Reproduction link

https://riddle.alibaba-inc.com/riddles/1e271717

Steps to reproduce

具体表现见 Riddle

问题描述:

  1. 页面刚渲染的时候,默认性别 男,但是 动态字段的 必填 * 没有显示出来
  2. 第一次点击 提交,显示 校验成功,但同时出现了 *
  3. 再次点击 提交,校验失败
  4. 切换 性别: 女,动态字段校验 * 消失,但是错误消息没有重置,此时点击 提交,仍然校验失败
jdkahn commented 5 years ago

Due to the nature of React, the field element initialization inside of FormItem will not occur in time for the later calls to this.field.getValues() to return the desired values. For your use case I would suggest manually calling this.field.init(...) at the top of the render function, setting the initValue prop here instead of using the defaultValue prop on the Input.

https://riddle.alibaba-inc.com/riddles/1aa36a67