Browse Source

docs: add getFieldsValue faq (#43405)

pull/43407/head
二货爱吃白萝卜 1 year ago
committed by GitHub
parent
commit
9fdf12ea47
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      components/form/index.en-US.md
  2. 4
      components/form/index.zh-CN.md

4
components/form/index.en-US.md

@ -545,6 +545,10 @@ In most case, we always recommend to use Form `initialValues`. Use Item `initial
1. Form `initialValues` is the first priority
2. Field `initialValue` is secondary \*. Does not work when multiple Item with same `name` setting the `initialValue`
### Why can't `getFieldsValue` get value at first render?
`getFieldsValue` returns collected field data by default, but the Form.Item node is not ready at the first render. You can get all field data by `getFieldsValue(true)`.
### Why does `onFieldsChange` trigger three times on change when field sets `rules`?
Validating is also part of the value updating. It pass follow steps:

4
components/form/index.zh-CN.md

@ -544,6 +544,10 @@ validator(rule, value, callback) => {
1. Form 的 `initialValues` 拥有最高优先级
2. Field 的 `initialValue` 次之 \*. 多个同 `name` Item 都设置 `initialValue` 时,则 Item 的 `initialValue` 不生效
### 为什么 `getFieldsValue` 在初次渲染的时候拿不到值?
`getFieldsValue` 默认返回收集的字段数据,而在初次渲染时 Form.Item 节点尚未渲染,因而无法收集到数据。你可以通过 `getFieldsValue(true)` 来获取所有字段数据。
### 为什么字段设置 `rules` 后更改值 `onFieldsChange` 会触发三次?
字段除了本身的值变化外,校验也是其状态之一。因而在触发字段变化会经历以下几个阶段:

Loading…
Cancel
Save