/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/forms/signals/src/api/rules/validation/validate.ts
43 строки
1 KB
SkyZeroZx
docs: add `@see` references to Signal Forms
06 июл 2026, 23:35
06 июл 2026, 23:35
bbbcf8f
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {addDefaultField} from '../../../field/validation'; import {FieldPathNode} from '../../../schema/path_node'; import {assertPathIsCurrent} from '../../../schema/schema'; import type { FieldContext, FieldValidator, PathKind, SchemaPath, SchemaPathRules, } from '../../types'; /** * Adds logic to a field to determine if the field has validation errors. * * @param path The target path to add the validation logic to. * @param logic A `Validator` that returns the current validation errors. * @template TValue The type of value stored in the field the logic is bound to. * @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array) * * @see [Custom validation rules](guide/forms/signals/validation#using-validate) * * @category logic * @publicApi 22.0 */ export function validate<TValue, TPathKind extends PathKind = PathKind.Root>( path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic: NoInfer<FieldValidator<TValue, TPathKind>>, ): void { assertPathIsCurrent(path); const pathNode = FieldPathNode.unwrapFieldPath(path); pathNode.builder.addSyncErrorRule((ctx) => { return addDefaultField(logic(ctx as FieldContext<TValue, TPathKind>), ctx.fieldTree); }); }