Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

shared-form.ts

30 lines949 Bytes

1import { formOptions } from '@tanstack/angular-form'
2​
3export const peopleFormOptions = formOptions({
4 defaultValues: {
5 fullName: '',
6 email: '',
7 phone: '',
8 address: { line1: '', line2: '', city: '', state: '', zip: '' },
9 emergencyContact: { fullName: '', phone: '' },
10 },
11 validators: [
12 {
13 triggers: ['change'],
14 run: async ({ value, createErrorMap }) => {
15 const errors = createErrorMap()
16 if (!value.fullName) errors.fields.fullName = 'Full name is required'
17 if (!value.phone) errors.fields.phone = 'Phone is required'
18 if (!value.emergencyContact.fullName) {
19 errors.fields['emergencyContact.fullName'] =
20 'Emergency contact full name is required'
21 }
22 if (!value.emergencyContact.phone) {
23 errors.fields['emergencyContact.phone'] =
24 'Emergency contact phone is required'
25 }
26 return errors
27 },
28 },
29 ],
30})