Skip to content

Commit ef742f9

Browse files
authored
Merge branch 'master' into chore/upgrade-async-validator
2 parents 6cc06cd + 0ed0e7b commit ef742f9

27 files changed

+737
-153
lines changed

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
version: 2
22
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
37
- package-ecosystem: npm
48
directory: "/"
59
schedule:

.github/workflows/main.yml

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ jobs:
1313
- name: checkout
1414
uses: actions/checkout@master
1515

16-
- uses: actions/setup-node@v1
16+
- uses: actions/setup-node@v4
1717
with:
18-
node-version: '16'
18+
node-version: '20'
1919

2020
- name: cache package-lock.json
21-
uses: actions/cache@v2
21+
uses: actions/cache@v4
2222
with:
2323
path: package-temp-dir
2424
key: lock-${{ github.sha }}
2525

2626
- name: create package-lock.json
27-
run: npm i --package-lock-only
27+
run: npm i --package-lock-only --legacy-peer-deps
2828

2929
- name: hack for singe file
3030
run: |
@@ -34,7 +34,7 @@ jobs:
3434
cp package-lock.json package-temp-dir
3535
- name: cache node_modules
3636
id: node_modules_cache_id
37-
uses: actions/cache@v2
37+
uses: actions/cache@v4
3838
with:
3939
path: node_modules
4040
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
@@ -47,16 +47,16 @@ jobs:
4747
runs-on: ubuntu-latest
4848
steps:
4949
- name: checkout
50-
uses: actions/checkout@master
50+
uses: actions/checkout@v4
5151

5252
- name: restore cache from package-lock.json
53-
uses: actions/cache@v2
53+
uses: actions/cache@v4
5454
with:
5555
path: package-temp-dir
5656
key: lock-${{ github.sha }}
5757

5858
- name: restore cache from node_modules
59-
uses: actions/cache@v2
59+
uses: actions/cache@v4
6060
with:
6161
path: node_modules
6262
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
@@ -70,16 +70,16 @@ jobs:
7070
runs-on: ubuntu-latest
7171
steps:
7272
- name: checkout
73-
uses: actions/checkout@master
73+
uses: actions/checkout@v4
7474

7575
- name: restore cache from package-lock.json
76-
uses: actions/cache@v2
76+
uses: actions/cache@v4
7777
with:
7878
path: package-temp-dir
7979
key: lock-${{ github.sha }}
8080

8181
- name: restore cache from node_modules
82-
uses: actions/cache@v2
82+
uses: actions/cache@v4
8383
with:
8484
path: node_modules
8585
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
@@ -93,21 +93,26 @@ jobs:
9393
runs-on: ubuntu-latest
9494
steps:
9595
- name: checkout
96-
uses: actions/checkout@master
96+
uses: actions/checkout@v4
9797

9898
- name: restore cache from package-lock.json
99-
uses: actions/cache@v2
99+
uses: actions/cache@v4
100100
with:
101101
path: package-temp-dir
102102
key: lock-${{ github.sha }}
103103

104104
- name: restore cache from node_modules
105-
uses: actions/cache@v2
105+
uses: actions/cache@v4
106106
with:
107107
path: node_modules
108108
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
109109

110110
- name: coverage
111-
run: npm test -- --coverage && bash <(curl -s https://codecov.io/bash)
111+
run: npm test -- --coverage
112+
113+
- uses: codecov/codecov-action@v4
114+
with:
115+
fail_ci_if_error: true # optional (default = false)
116+
token: ${{ secrets.CODECOV_TOKEN }} # required
112117

113118
needs: setup

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@
2727
.umi-test
2828
.env.local
2929
.dumi/
30+
package-lock.json

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ open http://localhost:8000
3535
```js | pure
3636
import Form, { Field } from 'rc-field-form';
3737

38-
const Input = ({ value = "", ...props }) => <input value={value} {...props} />;
38+
const Input = ({ value = '', ...props }) => <input value={value} {...props} />;
3939

4040
const Demo = () => {
4141
return (
4242
<Form
43-
onFinish={(values) => {
44-
console.log("Finish:", values);
43+
onFinish={values => {
44+
console.log('Finish:', values);
4545
}}
4646
>
4747
<Field name="username">
@@ -81,20 +81,20 @@ We use typescript to create the Type definition. You can view directly in IDE. B
8181

8282
### Field
8383

84-
| Prop | Description | Type | Default |
85-
| ----------------- | ----------------------------------------------------------------------------- | ------------------------------------------- | -------- |
86-
| dependencies | Will re-render if dependencies changed | [NamePath](#namepath)[] | - |
87-
| getValueFromEvent | Specify how to get value from event | (..args: any[]) => any | - |
88-
| getValueProps | Customize additional props with value. This prop will disable `valuePropName` | (value) => any | - |
89-
| initialValue | Field initial value | any | - |
90-
| name | Field name path | [NamePath](#namepath) | - |
91-
| normalize | Normalize value before update | (value, prevValue, prevValues) => any | - |
92-
| preserve | Preserve value when field removed | boolean | false |
93-
| rules | Validate rules | [Rule](#rule)[] | - |
84+
| Prop | Description | Type | Default |
85+
| ----------------- | ----------------------------------------------------------------------------- | ---------------------------------------------- | -------- |
86+
| dependencies | Will re-render if dependencies changed | [NamePath](#namepath)[] | - |
87+
| getValueFromEvent | Specify how to get value from event | (..args: any[]) => any | - |
88+
| getValueProps | Customize additional props with value. This prop will disable `valuePropName` | (value) => any | - |
89+
| initialValue | Field initial value | any | - |
90+
| name | Field name path | [NamePath](#namepath) | - |
91+
| normalize | Normalize value before update | (value, prevValue, prevValues) => any | - |
92+
| preserve | Preserve value when field removed | boolean | false |
93+
| rules | Validate rules | [Rule](#rule)[] | - |
9494
| shouldUpdate | Check if Field should update | boolean \| (prevValues, nextValues) => boolean | - |
95-
| trigger | Collect value update by event trigger | string | onChange |
96-
| validateTrigger | Config trigger point with rule validate | string \| string[] | onChange |
97-
| valuePropName | Config value mapping prop with element | string | value |
95+
| trigger | Collect value update by event trigger | string | onChange |
96+
| validateTrigger | Config trigger point with rule validate | string \| string[] | onChange |
97+
| valuePropName | Config value mapping prop with element | string | value |
9898

9999
### List
100100

docs/demo/clearOnDestroy.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## clearOnDestroy
2+
3+
<code src="../examples/clearOnDestroy.tsx"></code>

docs/demo/fieldTouched.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## fieldTouched
2+
3+
<code src="../examples/fieldTouched.tsx"></code>

docs/demo/useWatch-selector.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## useWatch-selector
2+
3+
<code src="../examples/useWatch-selector.tsx"></code>

docs/examples/clearOnDestroy.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import Form, { Field } from 'rc-field-form';
2+
import React, { useState } from 'react';
3+
import Input from './components/Input';
4+
5+
export default () => {
6+
const [load, setLoad] = useState(false);
7+
const [count, setCount] = useState(0);
8+
9+
const [form] = Form.useForm(undefined);
10+
11+
return (
12+
<>
13+
<button
14+
onClick={() => {
15+
setCount(c => c + 1);
16+
setLoad(c => !c);
17+
}}
18+
>
19+
load
20+
</button>
21+
22+
<button
23+
onClick={() => {
24+
console.log(form.getFieldsValue(true));
25+
}}
26+
>
27+
values
28+
</button>
29+
{load && (
30+
<Form form={form} initialValues={{ count }} clearOnDestroy>
31+
<Field name="count">
32+
<Input placeholder="count" />
33+
</Field>
34+
<button type="submit">Submit</button>
35+
</Form>
36+
)}
37+
</>
38+
);
39+
};

docs/examples/fieldTouched.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import React from 'react';
2+
import Form from 'rc-field-form';
3+
4+
export default () => {
5+
6+
const [form] = Form.useForm();
7+
const [, forceUpdate] = React.useState({});
8+
9+
return (
10+
<div>
11+
<Form
12+
form={form}
13+
style={{ padding: 20 }}
14+
initialValues={{
15+
usename: '123',
16+
list: [
17+
{},
18+
],
19+
}}
20+
>
21+
<Form.Field name="username">
22+
<input />
23+
</Form.Field>
24+
<div style={{ paddingLeft: 20 }}>
25+
<Form.List name="list">
26+
{(fields, { add }) => (
27+
<>
28+
{
29+
fields.map((field) => {
30+
return (
31+
<div key={field.key}>
32+
<div>
33+
<Form.Field name={[field.name, 'field1']}>
34+
<input placeholder="field1" />
35+
</Form.Field>
36+
</div>
37+
<div>
38+
<Form.Field name={[field.name, 'field2']}>
39+
<input placeholder="field2" />
40+
</Form.Field>
41+
</div>
42+
</div>
43+
);
44+
})
45+
}
46+
<button onClick={() => add()}>add</button>
47+
</>
48+
)}
49+
</Form.List>
50+
</div>
51+
<div>
52+
<button
53+
onClick={() => {
54+
forceUpdate({});
55+
}}
56+
>forceUpdate</button>
57+
<button
58+
onClick={() => form.resetFields()}
59+
>reset</button>
60+
</div>
61+
<div>form.isFieldsTouched(true): {`${form.isFieldsTouched(true)}`}</div>
62+
<div>{`form.isFieldsTouched(['list'], true)`}: {`${form.isFieldsTouched(['list'], true)}`}</div>
63+
</Form>
64+
</div>
65+
);
66+
}

docs/examples/useWatch-selector.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import Form, { Field } from 'rc-field-form';
3+
import Input from './components/Input';
4+
5+
type FieldType = {
6+
init?: string;
7+
name?: string;
8+
age?: number;
9+
};
10+
11+
export default () => {
12+
const [form] = Form.useForm<FieldType>();
13+
const values = Form.useWatch(
14+
values => ({ init: values.init, newName: values.name, newAge: values.age }),
15+
{ form, preserve: true },
16+
);
17+
console.log('values', values);
18+
return (
19+
<>
20+
<Form form={form} initialValues={{ init: 'init', name: 'aaa' }}>
21+
name
22+
<Field name="name">
23+
<Input />
24+
</Field>
25+
age
26+
<Field name="age">
27+
<Input />
28+
</Field>
29+
no-watch
30+
<Field name="no-watch">
31+
<Input />
32+
</Field>
33+
values:{JSON.stringify(values)}
34+
</Form>
35+
</>
36+
);
37+
};

0 commit comments

Comments
 (0)