Skip to content

optionalBlock

optionalBlock<T>(then, otherwise?): Schema<OptionalBlock<T, boolean>>

Defined in: projects/ngx-signal-schema/src/lib/structure/optional-block.ts:300

Creates a reusable schema for OptionalBlock<T>.

Use this when an API expects a Schema<OptionalBlock<T>>, for example in form(...), apply(...), or when composing reusable schemas.

Internally this applies the same optional-block behavior as applyOptional, but instead of applying it immediately to an existing fieldPath, it returns a schema that can be applied later.

The then inline rules or schema are applied to the block’s data node when meta.enabled evaluates to true.

If otherwise is provided, it is applied to the block’s data node when meta.enabled evaluates to false.

T

SchemaOrSchemaFn<T>

inline rules or schema applied when meta.enabled evaluates to true.

SchemaOrSchemaFn<T>

inline rules or schema applied when meta.enabled evaluates to false.

Schema<OptionalBlock<T, boolean>>

a reusable schema for an OptionalBlock<T>.

form(myOptionalBlockSignal, optionalBlock(SomeSchema, disabledHidden));

optionalBlock<T, K>(options): Schema<OptionalBlock<T, K>>

Defined in: projects/ngx-signal-schema/src/lib/structure/optional-block.ts:327

Creates a reusable schema for OptionalBlock<T, K>.

Use this overload when meta.enabled is not a boolean or when the enabled state needs custom evaluation logic via isEnabled.

This returns a schema. It does not apply rules to a concrete field immediately. If you already have a SchemaPath inside an existing schema(...), prefer applyOptional(...).

T

K = boolean

ApplyOptionalOptions<T, K>

configuration for the rules and the enabled-state evaluation.

Schema<OptionalBlock<T, K>>

a reusable schema for an OptionalBlock<T, K>.

const mySchema = optionalBlock({
then: SomeSchema,
otherwise: OtherSchema,
isEnabled: (val) => val === 'yes'
});