Skip to content

Commit 947bea7

Browse files
committed
Merge branch 'main' into fix-numeric-key-explode
2 parents c5b29f2 + 73eeabb commit 947bea7

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

examples/react/large-form/src/features/people/page.tsx

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,6 @@ import { peopleFormOpts } from './shared-form.tsx'
66
export const PeoplePage = () => {
77
const form = useAppForm({
88
...peopleFormOpts,
9-
validators: {
10-
onChange: ({ value }) => {
11-
const errors = {
12-
fields: {},
13-
} as {
14-
fields: Record<string, string>
15-
}
16-
if (!value.fullName) {
17-
errors.fields.fullName = 'Full name is required'
18-
}
19-
if (!value.phone) {
20-
errors.fields.phone = 'Phone is required'
21-
}
22-
if (!value.emergencyContact.fullName) {
23-
errors.fields['emergencyContact.fullName'] =
24-
'Emergency contact full name is required'
25-
}
26-
if (!value.emergencyContact.phone) {
27-
errors.fields['emergencyContact.phone'] =
28-
'Emergency contact phone is required'
29-
}
30-
31-
return errors
32-
},
33-
},
349
onSubmit: ({ value }) => {
3510
alert(JSON.stringify(value, null, 2))
3611
},

examples/react/large-form/src/features/people/shared-form.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,29 @@ export const peopleFormOpts = formOptions({
1717
phone: '',
1818
},
1919
},
20+
validators: {
21+
onChangeAsync: async ({ value }) => {
22+
const errors = {
23+
fields: {},
24+
} as {
25+
fields: Record<string, string>
26+
}
27+
if (!value.fullName) {
28+
errors.fields.fullName = 'Full name is required'
29+
}
30+
if (!value.phone) {
31+
errors.fields.phone = 'Phone is required'
32+
}
33+
if (!value.emergencyContact.fullName) {
34+
errors.fields['emergencyContact.fullName'] =
35+
'Emergency contact full name is required'
36+
}
37+
if (!value.emergencyContact.phone) {
38+
errors.fields['emergencyContact.phone'] =
39+
'Emergency contact phone is required'
40+
}
41+
42+
return errors
43+
},
44+
},
2045
})

0 commit comments

Comments
 (0)