-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into chore/upgrade-async-validator
- Loading branch information
Showing
27 changed files
with
737 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ | |
.umi-test | ||
.env.local | ||
.dumi/ | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## clearOnDestroy | ||
|
||
<code src="../examples/clearOnDestroy.tsx"></code> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## fieldTouched | ||
|
||
<code src="../examples/fieldTouched.tsx"></code> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## useWatch-selector | ||
|
||
<code src="../examples/useWatch-selector.tsx"></code> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Form, { Field } from 'rc-field-form'; | ||
import React, { useState } from 'react'; | ||
import Input from './components/Input'; | ||
|
||
export default () => { | ||
const [load, setLoad] = useState(false); | ||
const [count, setCount] = useState(0); | ||
|
||
const [form] = Form.useForm(undefined); | ||
|
||
return ( | ||
<> | ||
<button | ||
onClick={() => { | ||
setCount(c => c + 1); | ||
setLoad(c => !c); | ||
}} | ||
> | ||
load | ||
</button> | ||
|
||
<button | ||
onClick={() => { | ||
console.log(form.getFieldsValue(true)); | ||
}} | ||
> | ||
values | ||
</button> | ||
{load && ( | ||
<Form form={form} initialValues={{ count }} clearOnDestroy> | ||
<Field name="count"> | ||
<Input placeholder="count" /> | ||
</Field> | ||
<button type="submit">Submit</button> | ||
</Form> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React from 'react'; | ||
import Form from 'rc-field-form'; | ||
|
||
export default () => { | ||
|
||
const [form] = Form.useForm(); | ||
const [, forceUpdate] = React.useState({}); | ||
|
||
return ( | ||
<div> | ||
<Form | ||
form={form} | ||
style={{ padding: 20 }} | ||
initialValues={{ | ||
usename: '123', | ||
list: [ | ||
{}, | ||
], | ||
}} | ||
> | ||
<Form.Field name="username"> | ||
<input /> | ||
</Form.Field> | ||
<div style={{ paddingLeft: 20 }}> | ||
<Form.List name="list"> | ||
{(fields, { add }) => ( | ||
<> | ||
{ | ||
fields.map((field) => { | ||
return ( | ||
<div key={field.key}> | ||
<div> | ||
<Form.Field name={[field.name, 'field1']}> | ||
<input placeholder="field1" /> | ||
</Form.Field> | ||
</div> | ||
<div> | ||
<Form.Field name={[field.name, 'field2']}> | ||
<input placeholder="field2" /> | ||
</Form.Field> | ||
</div> | ||
</div> | ||
); | ||
}) | ||
} | ||
<button onClick={() => add()}>add</button> | ||
</> | ||
)} | ||
</Form.List> | ||
</div> | ||
<div> | ||
<button | ||
onClick={() => { | ||
forceUpdate({}); | ||
}} | ||
>forceUpdate</button> | ||
<button | ||
onClick={() => form.resetFields()} | ||
>reset</button> | ||
</div> | ||
<div>form.isFieldsTouched(true): {`${form.isFieldsTouched(true)}`}</div> | ||
<div>{`form.isFieldsTouched(['list'], true)`}: {`${form.isFieldsTouched(['list'], true)}`}</div> | ||
</Form> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import Form, { Field } from 'rc-field-form'; | ||
import Input from './components/Input'; | ||
|
||
type FieldType = { | ||
init?: string; | ||
name?: string; | ||
age?: number; | ||
}; | ||
|
||
export default () => { | ||
const [form] = Form.useForm<FieldType>(); | ||
const values = Form.useWatch( | ||
values => ({ init: values.init, newName: values.name, newAge: values.age }), | ||
{ form, preserve: true }, | ||
); | ||
console.log('values', values); | ||
return ( | ||
<> | ||
<Form form={form} initialValues={{ init: 'init', name: 'aaa' }}> | ||
name | ||
<Field name="name"> | ||
<Input /> | ||
</Field> | ||
age | ||
<Field name="age"> | ||
<Input /> | ||
</Field> | ||
no-watch | ||
<Field name="no-watch"> | ||
<Input /> | ||
</Field> | ||
values:{JSON.stringify(values)} | ||
</Form> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.