Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions examples/react/large-form/src/features/people/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,6 @@ import { peopleFormOpts } from './shared-form.tsx'
export const PeoplePage = () => {
const form = useAppForm({
...peopleFormOpts,
validators: {
onChange: ({ value }) => {
const errors = {
fields: {},
} as {
fields: Record<string, string>
}
if (!value.fullName) {
errors.fields.fullName = 'Full name is required'
}
if (!value.phone) {
errors.fields.phone = 'Phone is required'
}
if (!value.emergencyContact.fullName) {
errors.fields['emergencyContact.fullName'] =
'Emergency contact full name is required'
}
if (!value.emergencyContact.phone) {
errors.fields['emergencyContact.phone'] =
'Emergency contact phone is required'
}

return errors
},
},
onSubmit: ({ value }) => {
alert(JSON.stringify(value, null, 2))
},
Expand Down
25 changes: 25 additions & 0 deletions examples/react/large-form/src/features/people/shared-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,29 @@ export const peopleFormOpts = formOptions({
phone: '',
},
},
validators: {
onChangeAsync: async ({ value }) => {
const errors = {
fields: {},
} as {
fields: Record<string, string>
}
if (!value.fullName) {
errors.fields.fullName = 'Full name is required'
}
if (!value.phone) {
errors.fields.phone = 'Phone is required'
}
if (!value.emergencyContact.fullName) {
errors.fields['emergencyContact.fullName'] =
'Emergency contact full name is required'
}
if (!value.emergencyContact.phone) {
errors.fields['emergencyContact.phone'] =
'Emergency contact phone is required'
}

return errors
},
},
})
Loading