You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Form 的 resetFields 会重置为 undefined,而组件本身的清空则会是 null。两者区别在于 React 中组件 undefined 会被认为是非受控组件,所以在处理的时候会使用 null 表示清空(如果是用户删除的话,在 Input 这类组件则是空字符串)。而 Form 则是将 Form store 恢复成空对象,只是在收集 Fields 的时候遍历 store 中对应的路径组合成一个新对象返回,所以看起来是 undefiend 但是实际上真实的 Form Store 是空值,你可以通过 getFieldsValue(true) 查看真实的 Form Store 值。
Form 本身并不关注组件如果和实现清空的逻辑,其本身清空总是重置 Form Store。组件则可以实现自己的清空逻辑,而 antd 中如上述受控、非受控 因素选择 null 哈~
Reproduction link
https://ant.design/~demos/components-form-demo-nest-messages
Steps to reproduce
1、当第一次打开 demo,直接点击 submit,所有非必填项的值打印的都是 undefined
2、age 字段,随意输入一些值,再清空。然后打印的值变成了 null
3、其它字符串输入框,也随意输入一些值,再清空。然后打印的值变成了空字符串
What is expected?
因此,我个人认为,在上面三种情况中,它们被清空之后的值始终都应该保持为 undefined
What is actually happening?
实际情况中,并不一致
The text was updated successfully, but these errors were encountered: