-
-
Notifications
You must be signed in to change notification settings - Fork 280
Form.List name 不在 onFinish 取值中 #761
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
Changes from 10 commits
27328cb
1c2a469
673536c
cec82b3
e37a002
719b59b
6f2f069
a43a38a
7ffbcb0
3282cba
4e69d82
c7cdfb9
8c884da
1b32651
9ed569c
c14c2ff
d88e0d0
976b905
7a8800a
1d60c03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ## list | ||
|
|
||
| <code src="../examples/list-unmount.tsx"></code> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import React, { useState } from 'react'; | ||
| import Form from 'rc-field-form'; | ||
| import Input from './components/Input'; | ||
| import LabelField from './components/LabelField'; | ||
|
|
||
| const Demo = () => { | ||
| const [form] = Form.useForm(); | ||
| const [isShow, setIsShow] = useState(true); | ||
|
|
||
| return ( | ||
| <div> | ||
| <Form | ||
| form={form} | ||
| onFinish={values => { | ||
| console.log(JSON.stringify(values, null, 2)); | ||
| console.log(JSON.stringify(form.getFieldsValue({ strict: true }), null, 2)); | ||
crazyair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }} | ||
| initialValues={{ | ||
| users: [ | ||
| { name: 'a', age: '1' }, | ||
| { name: 'b', age: '2' }, | ||
| ], | ||
| }} | ||
| > | ||
| <Form.Field shouldUpdate>{() => JSON.stringify(form.getFieldsValue(), null, 2)}</Form.Field> | ||
|
|
||
| <Form.List name="users"> | ||
| {fields => { | ||
| return ( | ||
| <div> | ||
| {fields.map(field => ( | ||
| <div key={field.key} style={{ display: 'flex', gap: 10 }}> | ||
| <LabelField name={[field.name, 'name']}> | ||
| <Input /> | ||
| </LabelField> | ||
| {isShow && ( | ||
| <LabelField name={[field.name, 'age']}> | ||
| <Input /> | ||
| </LabelField> | ||
| )} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| }} | ||
| </Form.List> | ||
| <button type="button" onClick={() => setIsShow(c => !c)}> | ||
| 隐藏 | ||
| </button> | ||
| <button type="submit">Submit</button> | ||
| </Form> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default Demo; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -911,6 +911,8 @@ export class FormStore { | |
| ? nameList.map(getNamePath) | ||
| : []; | ||
|
|
||
| const removeListNameStrList: string[] = []; | ||
|
|
||
| // Collect result in promise list | ||
| const promiseList: Promise<FieldError>[] = []; | ||
|
|
||
|
|
@@ -921,9 +923,14 @@ export class FormStore { | |
| const { recursive, dirty } = options || {}; | ||
|
|
||
| this.getFieldEntities(true).forEach((field: FieldEntity) => { | ||
| const fieldNamePath = field.getNamePath(); | ||
|
|
||
| // Add field if not provide `nameList` | ||
| if (!provideNameList) { | ||
| namePathList.push(field.getNamePath()); | ||
| if (field.isList() && namePathList.some(name => matchNamePath(name, fieldNamePath, true))) { | ||
crazyair marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| removeListNameStrList.push(fieldNamePath.toString()); | ||
|
||
| } | ||
| namePathList.push(fieldNamePath); | ||
zombieJ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // Skip if without rule | ||
|
|
@@ -936,7 +943,6 @@ export class FormStore { | |
| return; | ||
| } | ||
|
|
||
| const fieldNamePath = field.getNamePath(); | ||
| validateNamePathList.add(fieldNamePath.join(TMP_SPLIT)); | ||
|
|
||
| // Add field validate rule in to promise list | ||
|
|
@@ -1000,7 +1006,10 @@ export class FormStore { | |
| const returnPromise: Promise<Store | ValidateErrorEntity | string[]> = summaryPromise | ||
| .then((): Promise<Store | string[]> => { | ||
| if (this.lastValidatePromise === summaryPromise) { | ||
| return Promise.resolve(this.getFieldsValue(namePathList)); | ||
| const filterListNameList = namePathList.filter( | ||
| name => !removeListNameStrList.some(nameStr => nameStr === name.toString()), | ||
| ); | ||
zombieJ marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return Promise.resolve(this.getFieldsValue(filterListNameList)); | ||
| } | ||
| return Promise.reject<string[]>([]); | ||
| }) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.