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

Validator.md

172 lines3.8 KB

1---
2id: Validator
3title: Validator
4---
5​
6Defined in: [validation.public.ts:41](https://github.com/TanStack/form/blob/main/packages/form-core/src/validation.public.ts#L41)
7​
8Configures validation for a form, form group, or field.
9​
10## Extends
11​
12- [`BaseValidator`](BaseValidator.md)\<`TValidator`\>
13​
14## Extended by
15​
16- [`FormGroupValidator`](FormGroupValidator.md)
17- [`FieldValidator`](FieldValidator.md)
18​
19## Type Parameters
20​
21### TFormData
22​
23`TFormData`
24​
25Library-managed. Do not specify explicitly.
26​
27### TValidator
28​
29`TValidator` *extends*
30 \| [`StandardSchemaV1`](../type-aliases/StandardSchemaV1.md)
31 \| [`ValidatorFn`](../type-aliases/ValidatorFn.md)\<`any`, `any`\>
32​
33Library-managed. Do not specify explicitly.
34​
35### TContextValue
36​
37`TContextValue`
38​
39Library-managed. Do not specify explicitly.
40​
41### TTrigger
42​
43`TTrigger` *extends* [`ValidatorTrigger`](../type-aliases/ValidatorTrigger.md) = [`ValidatorTrigger`](../type-aliases/ValidatorTrigger.md)
44​
45Library-managed. Do not specify explicitly.
46​
47### TScope
48​
49`TScope` *extends* [`ValidatorScope`](../type-aliases/ValidatorScope.md) = [`ValidatorScope`](../type-aliases/ValidatorScope.md)
50​
51Library-managed. Do not specify explicitly.
52​
53## Properties
54​
55### bailIfInvalid?
56​
57```ts
58optional bailIfInvalid?: boolean;
59```
60​
61Defined in: [validation.public.ts:29](https://github.com/TanStack/form/blob/main/packages/form-core/src/validation.public.ts#L29)
62​
63If `true`, skips this and subsequent validators when earlier validation has failed.
64​
65If `false`, earlier failures do not prevent this validator from running.
66​
67#### Default
68​
69```ts
70false
71```
72​
73#### Inherited from
74​
75[`BaseValidator`](BaseValidator.md).[`bailIfInvalid`](BaseValidator.md#bailifinvalid)
76​
77***
78​
79### run
80​
81```ts
82run: TValidator;
83```
84​
85Defined in: [validation.public.ts:21](https://github.com/TanStack/form/blob/main/packages/form-core/src/validation.public.ts#L21)
86​
87The function or Standard Schema that validates the value in this validator's scope.
88​
89#### Inherited from
90​
91[`BaseValidator`](BaseValidator.md).[`run`](BaseValidator.md#run)
92​
93***
94​
95### runOnMount?
96​
97```ts
98optional runOnMount?: boolean;
99```
100​
101Defined in: [validation.public.ts:64](https://github.com/TanStack/form/blob/main/packages/form-core/src/validation.public.ts#L64)
102​
103Whether this validator runs when the form is constructed or when its field
104or form group first mounts.
105​
106#### Default
107​
108```ts
109false
110```
111​
112***
113​
114### skipOnSubmit?
115​
116```ts
117optional skipOnSubmit?:
118 | boolean
119| ValidationPredicateFn<TFormData, TContextValue, TScope>;
120```
121​
122Defined in: [validation.public.ts:56](https://github.com/TanStack/form/blob/main/packages/form-core/src/validation.public.ts#L56)
123​
124Whether this validator runs during a submission attempt, independently of `triggers`.
125​
126Pass a boolean directly, or pass a function that returns
127`true` to skip it for the current attempt.
128​
129#### Default
130​
131```ts
132false
133```
134​
135***
136​
137### triggerDebounceMs?
138​
139```ts
140optional triggerDebounceMs?:
141 | number
142| ValidationDebounceFn<TFormData, TContextValue, TScope>;
143```
144​
145Defined in: [validation.public.ts:74](https://github.com/TanStack/form/blob/main/packages/form-core/src/validation.public.ts#L74)
146​
147The delay in milliseconds before validation runs for change or blur events.
148​
149Pass a number for a fixed delay, or pass a function that returns the delay
150for the current event. Repeated events restart the delay.
151Submission validation runs immediately.
152​
153#### Default
154​
155```ts
157```
158​
159***
160​
161### triggers
162​
163```ts
164triggers: ValidationTriggerOption<TFormData, TContextValue, TTrigger, TScope>[];
165```
166​
167Defined in: [validation.public.ts:82](https://github.com/TanStack/form/blob/main/packages/form-core/src/validation.public.ts#L82)
168​
169Change and blur events that can run this validator, optionally with conditions.
170​
171An empty array disables change and blur validation. Configure submission
172separately with `skipOnSubmit` and initial validation with `runOnMount`.