@tanstack/react-form 0.18.1 → 0.19.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-form",
3
- "version": "0.18.1",
3
+ "version": "0.19.0",
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.18.1"
46
+ "@tanstack/form-core": "0.19.0"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "react": "^17.0.0 || ^18.0.0"
@@ -802,4 +802,76 @@ describe('useField', () => {
802
802
  await user.click(await findByText('Submit'))
803
803
  expect(fn).toHaveBeenCalledWith({ people: [{ name: 'John', age: 0 }] })
804
804
  })
805
+
806
+ it('should handle sync linked fields', async () => {
807
+ const fn = vi.fn()
808
+ function Comp() {
809
+ const form = useForm({
810
+ defaultValues: {
811
+ password: '',
812
+ confirm_password: '',
813
+ },
814
+ onSubmit: ({ value }) => fn(value),
815
+ })
816
+
817
+ return (
818
+ <div>
819
+ <form.Field name="password">
820
+ {(field) => {
821
+ return (
822
+ <div>
823
+ <label>
824
+ <div>Password</div>
825
+ <input
826
+ value={field.state.value}
827
+ onChange={(e) => field.handleChange(e.target.value)}
828
+ />
829
+ </label>
830
+ </div>
831
+ )
832
+ }}
833
+ </form.Field>
834
+ <form.Field
835
+ name="confirm_password"
836
+ validators={{
837
+ onChangeListenTo: ['password'],
838
+ onChange: ({ value, fieldApi }) => {
839
+ if (value !== fieldApi.form.getFieldValue('password')) {
840
+ return 'Passwords do not match'
841
+ }
842
+ return undefined
843
+ },
844
+ }}
845
+ >
846
+ {(field) => {
847
+ return (
848
+ <div>
849
+ <label>
850
+ <div>Confirm Password</div>
851
+ <input
852
+ value={field.state.value}
853
+ onChange={(e) => field.handleChange(e.target.value)}
854
+ />
855
+ </label>
856
+ {field.state.meta.errors.map((err) => {
857
+ return <div key={err?.toString()}>{err}</div>
858
+ })}
859
+ </div>
860
+ )
861
+ }}
862
+ </form.Field>
863
+ </div>
864
+ )
865
+ }
866
+
867
+ const { findByLabelText, queryByText, findByText } = render(<Comp />)
868
+
869
+ const passwordInput = await findByLabelText('Password')
870
+ const confirmPasswordInput = await findByLabelText('Confirm Password')
871
+ await user.type(passwordInput, 'password')
872
+ await user.type(confirmPasswordInput, 'password')
873
+ expect(queryByText('Passwords do not match')).not.toBeInTheDocument()
874
+ await user.type(confirmPasswordInput, '1')
875
+ expect(await findByText('Passwords do not match')).toBeInTheDocument()
876
+ })
805
877
  })