/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/forms/signals/src/api/rules/readonly.ts
64 строки
2 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 {FieldPathNode} from '../../schema/path_node'; import {assertPathIsCurrent} from '../../schema/schema'; import type {LogicFn, PathKind, SchemaPath, SchemaPathRules} from '../types'; /** * Adds logic to a field to conditionally make it readonly. A readonly field does not contribute to * the validation, touched/dirty, or other state of its parent field. * * @param path The target path to make readonly. * @param config Optional configuration object. * - `when`: A reactive function that returns `true` when the field is readonly. * @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 [Readonly fields](guide/forms/signals/form-logic#display-uneditable-fields-with-readonly) * @see [Availability state](guide/forms/signals/field-state-management#availability-state) * * @category logic * @publicApi 22.0 */ export function readonly<TValue, TPathKind extends PathKind = PathKind.Root>( path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, config?: {when?: NoInfer<LogicFn<TValue, boolean, TPathKind>>}, ): void; /** * Adds logic to a field to conditionally make it readonly. * * @deprecated Passing a function directly to `readonly` is deprecated. Use `{ when: ... }` instead. */ export function readonly<TValue, TPathKind extends PathKind = PathKind.Root>( path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic?: NoInfer<LogicFn<TValue, boolean, TPathKind>>, ): void; export function readonly<TValue, TPathKind extends PathKind = PathKind.Root>( path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, configOrLogic?: | {when?: NoInfer<LogicFn<TValue, boolean, TPathKind>>} | NoInfer<LogicFn<TValue, boolean, TPathKind>>, ) { assertPathIsCurrent(path); const pathNode = FieldPathNode.unwrapFieldPath(path); let logic: LogicFn<TValue, boolean, TPathKind>; if (typeof configOrLogic === 'object' && configOrLogic !== null && 'when' in configOrLogic) { logic = configOrLogic.when ?? (() => true); } else if (typeof configOrLogic === 'function') { logic = configOrLogic; } else { logic = () => true; } pathNode.builder.addReadonlyRule(logic); }