docs: Add FAQ of form onFieldsChange (#23808)

This commit is contained in:
二货机器人 2020-05-01 16:20:37 +08:00 committed by GitHub
parent 5f2874b292
commit 58fcee34c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -325,6 +325,16 @@ 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 \*. Not work when multiple Item with same `name` setting the `initialValue`
### Why `onFieldsChange` trigger three times on change when field set `rules`?
Validating is also part of the value updating. It pass follow steps:
1. Trigger value change
2. Rule validating
3. Rule validated
In each `onFieldsChange`, you will get `false` > `true` > `false` with `isFieldValidating`.
<style>
.site-form-item-icon {
color: rgba(0, 0, 0, 0.25);

View File

@ -326,6 +326,16 @@ validator(rule, value, callback) => {
1. Form 的 `initialValues` 拥有最高优先级
2. Field 的 `initialValue` 次之 \*. 多个同 `name` Item 都设置 `initialValue` 时,则 Item 的 `initialValue` 不生效
### 为什么字段设置 `rules` 后更改值 `onFieldsChange` 会触发三次?
字段除了本身的值变化外,校验也是其状态之一。因而在触发字段变化会经历以下几个阶段:
1. Trigger value change
2. Rule validating
3. Rule validated
在触发过程中,调用 `isFieldValidating` 会经历 `false` > `true` > `false` 的变化过程。
<style>
.site-form-item-icon {
color: rgba(0, 0, 0, 0.25);