dynamic-forms / Class

FieldContextRegistryService

Decorators:@Injectable

Service that provides field evaluation context by combining field context with root form registry information.

This service should be provided at the component level to ensure proper isolation between different form instances.

Methods

createDisplayOnlyContext()

Creates an evaluation context for display-only components (text fields, pages) that don't have their own FieldContext.

This is useful for:

  • Text fields (display-only, not part of form schema)
  • Pages (containers that need to evaluate visibility logic)

Uses reactive form value access to allow logic re-evaluation when form values change.

Presentation
createDisplayOnlyContext(fieldPath: string, customFunctions?: Record<string, (context: EvaluationContext<unknown>) => unknown> | undefined, formId: string = 'default'): EvaluationContext<unknown>;
Parameters
NameTypeDescription
fieldPath
string

The key/path of the display-only component

customFunctions
Record<string, (context: EvaluationContext<unknown>) => unknown> | undefined

Optional custom functions for expression evaluation

formId
string

Optional form identifier (defaults to 'default')

Returns

createEvaluationContext()

Creates an evaluation context for a field by combining:

  • The field's current value
  • The root form value from the registry
  • The field path (if available from form context)
  • Custom functions (if provided)
Presentation
createEvaluationContext(fieldContext: RootFieldContext<TValue>, customFunctions?: Record<string, (context: EvaluationContext<unknown>) => unknown> | undefined, formId: string = 'default'): EvaluationContext<unknown>;
Parameters
NameTypeDescription
fieldContext
RootFieldContext<TValue>
customFunctions
Record<string, (context: EvaluationContext<unknown>) => unknown> | undefined
formId
string
Returns

createReactiveEvaluationContext()

Creates a REACTIVE evaluation context for logic functions.

Unlike createEvaluationContext, this method does NOT use untracked(), which allows logic functions (hidden, readonly, disabled, required) to create reactive dependencies on form values.

When a dependent field value changes, the logic function will be re-evaluated.

IMPORTANT: For this to work correctly, the form value signal should be registered with rootFormRegistry.registerFormValueSignal() BEFORE the form is created. This ensures the logic function can read form values during schema evaluation.

NOTE: This should ONLY be used for logic functions, not validators. Validators should use createEvaluationContext with untracked() to prevent infinite reactive loops. Validators with cross-field dependencies should be hoisted to form-level using validateTree.

Presentation
createReactiveEvaluationContext(fieldContext: RootFieldContext<TValue>, customFunctions?: Record<string, (context: EvaluationContext<unknown>) => unknown> | undefined, formId: string = 'default'): EvaluationContext<unknown>;
Parameters
NameTypeDescription
fieldContext
RootFieldContext<TValue>
customFunctions
Record<string, (context: EvaluationContext<unknown>) => unknown> | undefined
formId
string
Returns