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

FieldValidators.md

218 lines7.0 KB

1---
2id: FieldValidators
3title: FieldValidators
4---
5​
6# Interface: FieldValidators\<TParentData, TName, TFieldValidator, TFormValidator, TData\>
7​
8## Type Parameters
9​
10β€’ **TParentData**
11​
12β€’ **TName** *extends* [`DeepKeys`](DeepKeys.md)\<`TParentData`\>
13​
14β€’ **TFieldValidator** *extends* `Validator`\<[`DeepValue`](DeepValue.md)\<`TParentData`, `TName`\>, `unknown`\> \| `undefined` = `undefined`
15​
16β€’ **TFormValidator** *extends* `Validator`\<`TParentData`, `unknown`\> \| `undefined` = `undefined`
17​
18β€’ **TData** *extends* [`DeepValue`](DeepValue.md)\<`TParentData`, `TName`\> = [`DeepValue`](DeepValue.md)\<`TParentData`, `TName`\>
19​
20## Properties
21​
22### onBlur?
23​
24```ts
25optional onBlur: FieldValidateOrFn<TParentData, TName, TFieldValidator, TFormValidator, TData>;
26```
27​
28An optional function, that when run when subscribing to blur event of input.
29If `validatorAdapter` is passed, this may also accept a property from the respective adapter
30​
31#### Example
32​
33```ts
34`z.string().min(1)` if `zodAdapter` is passed
35```
36​
37#### Defined in
38​
39[packages/form-core/src/FieldApi.ts:196](https://github.com/TanStack/form/blob/a6313b7699753752ae30ff16c169e0b08c2369e8/packages/form-core/src/FieldApi.ts#L196)
40​
41***
42​
43### onBlurAsync?
44​
45```ts
46optional onBlurAsync: FieldAsyncValidateOrFn<TParentData, TName, TFieldValidator, TFormValidator, TData>;
47```
48​
49An optional property similar to `onBlur` but async validation. If `validatorAdapter`
50is passed, this may also accept a property from the respective adapter
51​
52#### Example
53​
54```ts
55`z.string().refine(async (val) => val.length > 3, { message: 'Testing 123' })` if `zodAdapter` is passed
56```
57​
58#### Defined in
59​
60[packages/form-core/src/FieldApi.ts:209](https://github.com/TanStack/form/blob/a6313b7699753752ae30ff16c169e0b08c2369e8/packages/form-core/src/FieldApi.ts#L209)
61​
62***
63​
64### onBlurAsyncDebounceMs?
65​
66```ts
67optional onBlurAsyncDebounceMs: number;
68```
69​
70An optional number to represent how long the `onBlurAsync` should wait before running
71​
72If set to a number larger than 0, will debounce the async validation event by this length of time in milliseconds
73​
74#### Defined in
75​
76[packages/form-core/src/FieldApi.ts:222](https://github.com/TanStack/form/blob/a6313b7699753752ae30ff16c169e0b08c2369e8/packages/form-core/src/FieldApi.ts#L222)
77​
78***
79​
80### onBlurListenTo?
81​
82```ts
83optional onBlurListenTo: unknown extends TParentData ? string : TParentData extends readonly any[] & IsTuple<TParentData> ? PrefixTupleAccessor<TParentData<TParentData>, AllowedIndexes<TParentData<TParentData>, never>, []> : TParentData extends any[] ? PrefixArrayAccessor<TParentData<TParentData>, [any]> : TParentData extends Date ? never : TParentData extends object ? PrefixObjectAccessor<TParentData<TParentData>, []> : TParentData extends string | number | bigint | boolean ? "" : never[];
84```
85​
86An optional list of field names that should trigger this field's `onBlur` and `onBlurAsync` events when its value changes
87​
88#### Defined in
89​
90[packages/form-core/src/FieldApi.ts:226](https://github.com/TanStack/form/blob/a6313b7699753752ae30ff16c169e0b08c2369e8/packages/form-core/src/FieldApi.ts#L226)
91​
92***
93​
94### onChange?
95​
96```ts
97optional onChange: FieldValidateOrFn<TParentData, TName, TFieldValidator, TFormValidator, TData>;
98```
99​
100An optional property that takes a `ValidateFn` which is a generic of `TData` and `TParentData`.
101If `validatorAdapter` is passed, this may also accept a property from the respective adapter
102​
103#### Example
104​
105```ts
106`z.string().min(1)` if `zodAdapter` is passed
107```
108​
109#### Defined in
110​
111[packages/form-core/src/FieldApi.ts:160](https://github.com/TanStack/form/blob/a6313b7699753752ae30ff16c169e0b08c2369e8/packages/form-core/src/FieldApi.ts#L160)
112​
113***
114​
115### onChangeAsync?
116​
117```ts
118optional onChangeAsync: FieldAsyncValidateOrFn<TParentData, TName, TFieldValidator, TFormValidator, TData>;
119```
120​
121An optional property similar to `onChange` but async validation. If `validatorAdapter`
122is passed, this may also accept a property from the respective adapter
123​
124#### Example
125​
126```ts
127`z.string().refine(async (val) => val.length > 3, { message: 'Testing 123' })` if `zodAdapter` is passed
128```
129​
130#### Defined in
131​
132[packages/form-core/src/FieldApi.ts:173](https://github.com/TanStack/form/blob/a6313b7699753752ae30ff16c169e0b08c2369e8/packages/form-core/src/FieldApi.ts#L173)
133​
134***
135​
136### onChangeAsyncDebounceMs?
137​
138```ts
139optional onChangeAsyncDebounceMs: number;
140```
141​
142An optional number to represent how long the `onChangeAsync` should wait before running
143​
144If set to a number larger than 0, will debounce the async validation event by this length of time in milliseconds
145​
146#### Defined in
147​
148[packages/form-core/src/FieldApi.ts:185](https://github.com/TanStack/form/blob/a6313b7699753752ae30ff16c169e0b08c2369e8/packages/form-core/src/FieldApi.ts#L185)
149​
150***
151​
152### onChangeListenTo?
153​
154```ts
155optional onChangeListenTo: unknown extends TParentData ? string : TParentData extends readonly any[] & IsTuple<TParentData> ? PrefixTupleAccessor<TParentData<TParentData>, AllowedIndexes<TParentData<TParentData>, never>, []> : TParentData extends any[] ? PrefixArrayAccessor<TParentData<TParentData>, [any]> : TParentData extends Date ? never : TParentData extends object ? PrefixObjectAccessor<TParentData<TParentData>, []> : TParentData extends string | number | bigint | boolean ? "" : never[];
156```
157​
158An optional list of field names that should trigger this field's `onChange` and `onChangeAsync` events when its value changes
159​
160#### Defined in
161​
162[packages/form-core/src/FieldApi.ts:189](https://github.com/TanStack/form/blob/a6313b7699753752ae30ff16c169e0b08c2369e8/packages/form-core/src/FieldApi.ts#L189)
163​
164***
165​
166### onMount?
167​
168```ts
169optional onMount: FieldValidateOrFn<TParentData, TName, TFieldValidator, TFormValidator, TData>;
170```
171​
172An optional function that takes a param of `formApi` which is a generic type of `TData` and `TParentData`
173​
174#### Defined in
175​
176[packages/form-core/src/FieldApi.ts:147](https://github.com/TanStack/form/blob/a6313b7699753752ae30ff16c169e0b08c2369e8/packages/form-core/src/FieldApi.ts#L147)
177​
178***
179​
180### onSubmit?
181​
182```ts
183optional onSubmit: FieldValidateOrFn<TParentData, TName, TFieldValidator, TFormValidator, TData>;
184```
185​
186An optional function, that when run when subscribing to submit event of input.
187If `validatorAdapter` is passed, this may also accept a property from the respective adapter
188​
189#### Example
190​
191```ts
192`z.string().min(1)` if `zodAdapter` is passed
193```
194​
195#### Defined in
196​
197[packages/form-core/src/FieldApi.ts:233](https://github.com/TanStack/form/blob/a6313b7699753752ae30ff16c169e0b08c2369e8/packages/form-core/src/FieldApi.ts#L233)
198​
199***
200​
201### onSubmitAsync?
202​
203```ts
204optional onSubmitAsync: FieldAsyncValidateOrFn<TParentData, TName, TFieldValidator, TFormValidator, TData>;
205```
206​
207An optional property similar to `onSubmit` but async validation. If `validatorAdapter`
208is passed, this may also accept a property from the respective adapter
209​
210#### Example
211​
212```ts
213`z.string().refine(async (val) => val.length > 3, { message: 'Testing 123' })` if `zodAdapter` is passed
214```
215​
216#### Defined in
217​
218[packages/form-core/src/FieldApi.ts:246](https://github.com/TanStack/form/blob/a6313b7699753752ae30ff16c169e0b08c2369e8/packages/form-core/src/FieldApi.ts#L246)