@tanstack/react-form 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/tests/useField.test.tsx +47 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-form",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "Powerful, type-safe forms for React.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@tanstack/react-store": "0.1.3",
|
|
55
55
|
"@tanstack/store": "0.1.3",
|
|
56
56
|
"use-isomorphic-layout-effect": "^1.1.2",
|
|
57
|
-
"@tanstack/form-core": "0.3.
|
|
57
|
+
"@tanstack/form-core": "0.3.7"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"react": "^17.0.0 || ^18.0.0",
|
|
@@ -18,13 +18,17 @@ describe('useField', () => {
|
|
|
18
18
|
const formFactory = createFormFactory<Person>()
|
|
19
19
|
|
|
20
20
|
function Comp() {
|
|
21
|
-
const form = formFactory.useForm(
|
|
21
|
+
const form = formFactory.useForm({
|
|
22
|
+
defaultValues: {
|
|
23
|
+
firstName: 'FirstName',
|
|
24
|
+
lastName: 'LastName',
|
|
25
|
+
},
|
|
26
|
+
})
|
|
22
27
|
|
|
23
28
|
return (
|
|
24
29
|
<form.Provider>
|
|
25
30
|
<form.Field
|
|
26
31
|
name="firstName"
|
|
27
|
-
defaultValue="FirstName"
|
|
28
32
|
children={(field) => {
|
|
29
33
|
return (
|
|
30
34
|
<input
|
|
@@ -45,6 +49,47 @@ describe('useField', () => {
|
|
|
45
49
|
expect(input).toHaveValue('FirstName')
|
|
46
50
|
})
|
|
47
51
|
|
|
52
|
+
it('should use field default value first', async () => {
|
|
53
|
+
type Person = {
|
|
54
|
+
firstName: string
|
|
55
|
+
lastName: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const formFactory = createFormFactory<Person>()
|
|
59
|
+
|
|
60
|
+
function Comp() {
|
|
61
|
+
const form = formFactory.useForm({
|
|
62
|
+
defaultValues: {
|
|
63
|
+
firstName: 'FirstName',
|
|
64
|
+
lastName: 'LastName',
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<form.Provider>
|
|
70
|
+
<form.Field
|
|
71
|
+
name="firstName"
|
|
72
|
+
defaultValue="otherName"
|
|
73
|
+
children={(field) => {
|
|
74
|
+
return (
|
|
75
|
+
<input
|
|
76
|
+
data-testid="fieldinput"
|
|
77
|
+
value={field.state.value}
|
|
78
|
+
onBlur={field.handleBlur}
|
|
79
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
80
|
+
/>
|
|
81
|
+
)
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
84
|
+
</form.Provider>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const { getByTestId } = render(<Comp />)
|
|
89
|
+
const input = getByTestId('fieldinput')
|
|
90
|
+
expect(input).toHaveValue('otherName')
|
|
91
|
+
})
|
|
92
|
+
|
|
48
93
|
it('should not validate on change if isTouched is false', async () => {
|
|
49
94
|
type Person = {
|
|
50
95
|
firstName: string
|