File tree Expand file tree Collapse file tree 2 files changed +25
-25
lines changed
examples/react/large-form/src/features/people Expand file tree Collapse file tree 2 files changed +25
-25
lines changed Original file line number Diff line number Diff line change @@ -6,31 +6,6 @@ import { peopleFormOpts } from './shared-form.tsx'
66export 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 } ,
Original file line number Diff line number Diff 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} )
You can’t perform that action at this time.
0 commit comments