@tanstack/react-form 0.19.3 → 0.19.4
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 +57 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-form",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.4",
|
|
4
4
|
"description": "Powerful, type-safe forms for React.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@tanstack/react-store": "^0.3.1",
|
|
44
44
|
"decode-formdata": "^0.4.0",
|
|
45
45
|
"rehackt": "^0.0.3",
|
|
46
|
-
"@tanstack/form-core": "0.19.
|
|
46
|
+
"@tanstack/form-core": "0.19.4"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"react": "^17.0.0 || ^18.0.0"
|
|
@@ -900,4 +900,61 @@ describe('useField', () => {
|
|
|
900
900
|
expect(queryByText('Test')).not.toBeInTheDocument()
|
|
901
901
|
expect(await findByText('User')).toBeInTheDocument()
|
|
902
902
|
})
|
|
903
|
+
|
|
904
|
+
it('should validate async on submit without debounce', async () => {
|
|
905
|
+
type Person = {
|
|
906
|
+
firstName: string
|
|
907
|
+
lastName: string
|
|
908
|
+
}
|
|
909
|
+
const mockFn = vi.fn()
|
|
910
|
+
const error = 'Please enter a different value'
|
|
911
|
+
const formFactory = createFormFactory<Person>()
|
|
912
|
+
|
|
913
|
+
function Comp() {
|
|
914
|
+
const form = formFactory.useForm({
|
|
915
|
+
defaultValues: {
|
|
916
|
+
firstName: '',
|
|
917
|
+
lastName: '',
|
|
918
|
+
},
|
|
919
|
+
validators: {
|
|
920
|
+
onChangeAsyncDebounceMs: 1000000,
|
|
921
|
+
onChangeAsync: async () => {
|
|
922
|
+
mockFn()
|
|
923
|
+
await sleep(10)
|
|
924
|
+
return error
|
|
925
|
+
},
|
|
926
|
+
},
|
|
927
|
+
})
|
|
928
|
+
const errors = form.useStore((s) => s.errors)
|
|
929
|
+
|
|
930
|
+
return (
|
|
931
|
+
<>
|
|
932
|
+
<form.Field
|
|
933
|
+
name="firstName"
|
|
934
|
+
defaultMeta={{ isTouched: true }}
|
|
935
|
+
children={(field) => (
|
|
936
|
+
<div>
|
|
937
|
+
<input
|
|
938
|
+
data-testid="fieldinput"
|
|
939
|
+
name={field.name}
|
|
940
|
+
value={field.state.value}
|
|
941
|
+
onBlur={field.handleBlur}
|
|
942
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
943
|
+
/>
|
|
944
|
+
<p>{errors}</p>
|
|
945
|
+
</div>
|
|
946
|
+
)}
|
|
947
|
+
/>
|
|
948
|
+
<button onClick={form.handleSubmit}>Submit</button>
|
|
949
|
+
</>
|
|
950
|
+
)
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
const { getByRole, getByText } = render(<Comp />)
|
|
954
|
+
await user.click(getByRole('button', { name: 'Submit' }))
|
|
955
|
+
|
|
956
|
+
expect(mockFn).toHaveBeenCalledTimes(1)
|
|
957
|
+
await waitFor(() => getByText(error))
|
|
958
|
+
expect(getByText(error)).toBeInTheDocument()
|
|
959
|
+
})
|
|
903
960
|
})
|