optionalBlock
Call Signature
Section titled “Call Signature”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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”SchemaOrSchemaFn<T>
inline rules or schema applied when meta.enabled evaluates to true.
otherwise?
Section titled “otherwise?”SchemaOrSchemaFn<T>
inline rules or schema applied when meta.enabled evaluates to false.
Returns
Section titled “Returns”Schema<OptionalBlock<T, boolean>>
a reusable schema for an OptionalBlock<T>.
Example
Section titled “Example”form(myOptionalBlockSignal, optionalBlock(SomeSchema, disabledHidden));Call Signature
Section titled “Call Signature”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(...).
Type Parameters
Section titled “Type Parameters”T
K = boolean
Parameters
Section titled “Parameters”options
Section titled “options”ApplyOptionalOptions<T, K>
configuration for the rules and the enabled-state evaluation.
Returns
Section titled “Returns”Schema<OptionalBlock<T, K>>
a reusable schema for an OptionalBlock<T, K>.
Example
Section titled “Example”const mySchema = optionalBlock({ then: SomeSchema, otherwise: OtherSchema, isEnabled: (val) => val === 'yes'});