applyOptional
Call Signature
Section titled “Call Signature”applyOptional<
T>(fieldPath,then,otherwise?):void
Defined in: projects/ngx-signal-schema/src/lib/structure/optional-block.ts:205
Applies rules or a schema directly to the data node of a concrete OptionalBlock field.
Use this inside an existing schema(...) when you already have a SchemaPath
to an OptionalBlock<T>.
The then inline rules or schema are applied to fieldPath.data when
meta.enabled evaluates to true.
If otherwise is provided, it is applied to fieldPath.data when
meta.enabled evaluates to false.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”fieldPath
Section titled “fieldPath”SchemaPath<OptionalBlock<T, boolean>>
path to the concrete OptionalBlock<T> field.
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”void
Example
Section titled “Example”schema<MyModel>((fieldPath) => { applyOptional(fieldPath.someOptionalBlock, SomeSchema, disabledHidden);});Call Signature
Section titled “Call Signature”applyOptional<
T,K>(fieldPath,options):void
Defined in: projects/ngx-signal-schema/src/lib/structure/optional-block.ts:234
Applies rules or a schema directly to the data node of a concrete OptionalBlock field.
Use this overload when meta.enabled is not a boolean or when the enabled state
needs custom evaluation logic via isEnabled.
This function does not create a reusable schema. It applies the optional-block
behavior immediately to the given fieldPath.
Type Parameters
Section titled “Type Parameters”T
K = boolean
Parameters
Section titled “Parameters”fieldPath
Section titled “fieldPath”SchemaPath<OptionalBlock<T, K>>
path to the concrete OptionalBlock<T, K> field.
options
Section titled “options”ApplyOptionalOptions<T, K>
configuration for the rules and the enabled-state evaluation.
Returns
Section titled “Returns”void
Example
Section titled “Example”schema<MyModel>((fieldPath) => { applyOptional(fieldPath.statusBlock, { then: StatusActiveSchema, isEnabled: (status) => status === 'ACTIVE' });});