Open History to see the last commit
1import { reconcileValidatorInstances } from '@tanstack/form-core/internals'
2import type { AnyInternalFieldApi } from '@tanstack/form-core/internals'
3import type { ValidationIssue } from '@tanstack/form-core'
4β
5export function setFieldValidatorErrors(
6 field: AnyInternalFieldApi,
7 errors: Array<ValidationIssue>,
8 sourceEvent = 'change',
9): void {
10 field._validatorInstances ??= reconcileValidatorInstances({
11 definitions: [{ run: () => null, triggers: ['change'] }],
12 instances: null,
13 owner: field,
14 scope: 'field',
15 })
16 const validatorInstance = field._validatorInstances![0]!
17β
18 field._setMeta((meta) => ({
19 ...meta,
20 _validationSourceErrors:
21 errors.length > 0
22 ? new Map([[validatorInstance, { errors, sourceEvent }]])
23 : null,
24 }))
25}