diff --git a/packages/forms/signals/src/api/rules/disabled.ts b/packages/forms/signals/src/api/rules/disabled.ts index 9b088854a24..1ebb1abed09 100644 --- a/packages/forms/signals/src/api/rules/disabled.ts +++ b/packages/forms/signals/src/api/rules/disabled.ts @@ -15,7 +15,7 @@ import type {FieldContext, LogicFn, PathKind, SchemaPath, SchemaPathRules} from * validation, touched/dirty, or other state of its parent field. * * @param path The target path to add the disabled logic to. - * @param configOrLogic Optional configuration object containing `when`, or the logic directly (deprecated). + * @param config Optional configuration object. * - `when`: A reactive function that returns `true` (or a string reason) when the field is disabled, * and `false` when it is not disabled. Can also be a static string reason. * @template TValue The type of value stored in the field the logic is bound to. @@ -24,6 +24,21 @@ import type {FieldContext, LogicFn, PathKind, SchemaPath, SchemaPathRules} from * @category logic * @publicApi 22.0 */ +export function disabled( + path: SchemaPath, + config?: {when?: string | NoInfer>}, +): void; + +/** + * Adds logic to a field to conditionally disable it. + * + * @deprecated Passing a function or string directly to `disabled` is deprecated. Use `{ when: ... }` instead. + */ +export function disabled( + path: SchemaPath, + logic?: string | NoInfer>, +): void; + export function disabled( path: SchemaPath, configOrLogic?: @@ -38,15 +53,8 @@ export function disabled( let logic: string | LogicFn | undefined; if (typeof configOrLogic === 'function' || typeof configOrLogic === 'string') { logic = configOrLogic; - if (typeof ngDevMode === 'undefined' || ngDevMode) { - console.warn( - `[Signal Forms] Passing a function or string directly to 'disabled' is deprecated. Use '{ when: ... }' instead.`, - ); - } - } else if (configOrLogic !== undefined) { - logic = configOrLogic.when; } else { - logic = undefined; + logic = configOrLogic?.when; } pathNode.builder.addDisabledReasonRule((ctx) => { diff --git a/packages/forms/signals/src/api/rules/hidden.ts b/packages/forms/signals/src/api/rules/hidden.ts index 69db195875b..5624133cc9a 100644 --- a/packages/forms/signals/src/api/rules/hidden.ts +++ b/packages/forms/signals/src/api/rules/hidden.ts @@ -23,7 +23,7 @@ import type {LogicFn, PathKind, SchemaPath, SchemaPathRules} from '../types'; * ``` * * @param path The target path to add the hidden logic to. - * @param configOrLogic Options object containing the `when` condition, or the logic function directly (deprecated). + * @param config Options object containing the `when` condition. * - `when`: A reactive function that returns `true` when the field is hidden. * @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) @@ -31,6 +31,21 @@ import type {LogicFn, PathKind, SchemaPath, SchemaPathRules} from '../types'; * @category logic * @publicApi 22.0 */ +export function hidden( + path: SchemaPath, + config: {when: NoInfer>}, +): void; + +/** + * Adds logic to a field to conditionally hide it. + * + * @deprecated Passing a function directly to `hidden` is deprecated. Use `{ when: ... }` instead. + */ +export function hidden( + path: SchemaPath, + logic: NoInfer>, +): void; + export function hidden( path: SchemaPath, configOrLogic: @@ -41,17 +56,7 @@ export function hidden( const pathNode = FieldPathNode.unwrapFieldPath(path); - let logic: LogicFn; - if (typeof configOrLogic === 'function') { - logic = configOrLogic; - if (typeof ngDevMode === 'undefined' || ngDevMode) { - console.warn( - `[Signal Forms] Passing a function directly to 'hidden' is deprecated. Use '{ when: ... }' instead.`, - ); - } - } else { - logic = configOrLogic.when; - } + const logic = typeof configOrLogic === 'function' ? configOrLogic : configOrLogic.when; pathNode.builder.addHiddenRule(logic); } diff --git a/packages/forms/signals/src/api/rules/readonly.ts b/packages/forms/signals/src/api/rules/readonly.ts index 38402ceb51f..e1f653009a5 100644 --- a/packages/forms/signals/src/api/rules/readonly.ts +++ b/packages/forms/signals/src/api/rules/readonly.ts @@ -15,7 +15,7 @@ import type {LogicFn, PathKind, SchemaPath, SchemaPathRules} from '../types'; * the validation, touched/dirty, or other state of its parent field. * * @param path The target path to make readonly. - * @param configOrLogic Optional configuration object containing `when`, or the logic directly (deprecated). + * @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) @@ -23,6 +23,21 @@ import type {LogicFn, PathKind, SchemaPath, SchemaPathRules} from '../types'; * @category logic * @publicApi 22.0 */ +export function readonly( + path: SchemaPath, + config?: {when?: NoInfer>}, +): 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( + path: SchemaPath, + logic?: NoInfer>, +): void; + export function readonly( path: SchemaPath, configOrLogic?: @@ -38,11 +53,6 @@ export function readonly( logic = configOrLogic.when ?? (() => true); } else if (typeof configOrLogic === 'function') { logic = configOrLogic; - if (typeof ngDevMode === 'undefined' || ngDevMode) { - console.warn( - `[Signal Forms] Passing a function directly to 'readonly' is deprecated. Use '{ when: ... }' instead.`, - ); - } } else { logic = () => true; } diff --git a/packages/forms/signals/test/node/api/hidden.spec.ts b/packages/forms/signals/test/node/api/hidden.spec.ts index 294191ad5b7..3a6ed8df0e1 100644 --- a/packages/forms/signals/test/node/api/hidden.spec.ts +++ b/packages/forms/signals/test/node/api/hidden.spec.ts @@ -128,24 +128,15 @@ describe('hidden', () => { it('supports deprecated function syntax', () => { const cat = signal({name: 'Pirojok-the-cat', age: 5}); - const spy = jasmine.createSpy('console.warn'); - const originalWarn = console.warn; - console.warn = spy; + const f = form( + cat, + (p) => { + hidden(p.name, ((ctx: any) => ctx.value() === 'hidden-cat') as any); + }, + {injector: TestBed.inject(Injector)}, + ); - try { - const f = form( - cat, - (p) => { - hidden(p.name, ((ctx: any) => ctx.value() === 'hidden-cat') as any); - }, - {injector: TestBed.inject(Injector)}, - ); - - f.name().value.set('hidden-cat'); - expect(f.name().hidden()).toBe(true); - expect(spy).toHaveBeenCalled(); - } finally { - console.warn = originalWarn; - } + f.name().value.set('hidden-cat'); + expect(f.name().hidden()).toBe(true); }); });