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

FormSubmitContext.md

166 lines3.3 KB

1---
2id: FormSubmitContext
3title: FormSubmitContext
4---
5​
6Defined in: [FormApi/FormApi.public.ts:105](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi/FormApi.public.ts#L105)
7​
8Context passed to `onSubmit` after submission validation succeeds.
9​
10## Example
11​
12```ts
14 // ...
15 onSubmit: async ({ value, createValidationError }) => {
16 const result = await saveUser(value)
17​
18 if (!result.ok) {
19 return createValidationError(result.error)
20 }
21 },
23```
24​
25## Type Parameters
26​
27### TFormData
28​
29`TFormData`
30​
31Library-managed. Do not specify explicitly.
32​
33### TOutputs
34​
35`TOutputs`
36​
37Library-managed. Do not specify explicitly.
38​
39### TFormErrorTypes
40​
41`TFormErrorTypes` *extends* [`FormErrorTypes`](FormErrorTypes.md)
42​
43Library-managed. Do not specify explicitly.
44​
45## Properties
46​
47### createErrorMap
48​
49```ts
50createErrorMap: CreateSubmitErrorMapFn<TFormData>;
51```
52​
53Defined in: [FormApi/FormApi.public.ts:155](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi/FormApi.public.ts#L155)
54​
55***
56​
57### createValidationError
58​
59```ts
60createValidationError: CreateValidationErrorFn<TFormData>;
61```
62​
63Defined in: [FormApi/FormApi.public.ts:154](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi/FormApi.public.ts#L154)
64​
65Creates a validation error that can be returned from `onSubmit`.
66​
67Return the created error from `onSubmit` to add its form- and field-level
68errors to validation state.
69​
70#### Example
71​
72```ts
74 // ...
75 onSubmit: async ({ value, createValidationError }) => {
76 const result = await saveUser(value)
77​
78 if (result.status === 409) {
79 return createValidationError({
80 form: 'A user with this email already exists',
81 fields: {},
82 })
83 }
84 },
86```
87​
88***
89​
90### formApi
91​
92```ts
93formApi: FormApi<TFormData, TFormErrorTypes>;
94```
95​
96Defined in: [FormApi/FormApi.public.ts:113](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi/FormApi.public.ts#L113)
97​
98The form API handling this submission.
99​
100***
101​
102### parseIssues
103​
104```ts
105parseIssues: ParseSubmitIssuesFn<TFormData>;
106```
107​
108Defined in: [FormApi/FormApi.public.ts:176](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi/FormApi.public.ts#L176)
109​
110Parses Standard Schema issues into an error returnable from `onSubmit`.
111​
112Issue paths are mapped to fields in the submitted value. Return the parsed
113error from `onSubmit` to add those errors to validation state.
114​
115#### Example
116​
117```ts
119 // ...
120 onSubmit: async ({ value, parseIssues }) => {
121 const result = zodSchema.safeParse(value)
122​
123 if (!result.success) {
124 return parseIssues(result.error.issues)
125 }
126 },
128```
129​
130***
131​
132### validatorOutputs
133​
134```ts
135validatorOutputs: TOutputs;
136```
137​
138Defined in: [FormApi/FormApi.public.ts:130](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi/FormApi.public.ts#L130)
139​
140Schema outputs and `createOutput` payloads from this submission, ordered by
141validator index. Skipped validators and successful returns without an output
142contribute `undefined`.
143​
144#### Example
145​
146```ts
148 // ...
149 onSubmit: async ({ validatorOutputs }) => {
150 const validatedUser = validatorOutputs[0]
151 await saveUser(validatedUser)
152 },
154```
155​
156***
157​
158### value
159​
160```ts
161value: TFormData;
162```
163​
164Defined in: [FormApi/FormApi.public.ts:111](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi/FormApi.public.ts#L111)
165​
166The form values for this submission.