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

createValidator.md

46 lines1.2 KB

1---
2id: createValidator
3title: createValidator
4---
5​
6```ts
7function createValidator<TOptions>(options): <TValidator>(run) => CreatedValidator<TOptions, TValidator>;
8```
9​
10Defined in: [validation.public.ts:195](https://github.com/TanStack/form/blob/main/packages/form-core/src/validation.public.ts#L195)
11​
12Creates a reusable configuration to apply to validation functions or Standard Schemas.
13​
14## Type Parameters
15​
16### TOptions
17​
18`TOptions` *extends* [`ValidatorOptions`](../type-aliases/ValidatorOptions.md)\<`any`, `any`, [`ConfigurableValidationTrigger`](../type-aliases/ConfigurableValidationTrigger.md), [`ValidatorScope`](../type-aliases/ValidatorScope.md)\>
19​
20Library-managed. Do not specify explicitly.
21​
22## Parameters
23​
24### options
25​
26`TOptions`
27​
28## Returns
29​
30A function that combines `options` with its `run` argument, preserving
31the validator's inferred types. Its `TValidator` type argument is library-managed.
32Do not specify it explicitly.
33​
34\<`TValidator`\>(`run`) => [`CreatedValidator`](../type-aliases/CreatedValidator.md)\<`TOptions`, `TValidator`\>
35​
36## Example
37​
38```ts
39const afterSubmit = createValidator({
40 triggers: [{
41 trigger: 'change',
42 when: ({ formApi }) => formApi.state.submissionAttempts > 0,
43 }],
44})
45const validators = [afterSubmit(schema)]
46```