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

shared-form.ts

39 lines991 Bytes

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