Class

NgxFormFieldDirective

lib/engine/NgxFormFieldDirective~NgxFormFieldDirective()

Constructor

# new NgxFormFieldDirective()

Provides the foundation for all form field components in Decaf applications by implementing Angular's ControlValueAccessor interface and FieldProperties for validation. This directive manages form control integration, validation state, multi-entry forms (FormArrays), and CRUD operation context. It handles form group lifecycle, error messaging, change detection, and parent-child form relationships. Extend this class to create custom form field components that seamlessly integrate with Angular's reactive forms and Decaf's validation system.

Abstract base directive for CRUD form fields in Angular applications.

Implements:
  • ControlValueAccessor
  • FieldProperties

View Source lib/engine/NgxFormFieldDirective.ts, line 27

Example
```typescript

Extends

Members

# activeFormGroup

Returns the appropriate FormGroup based on whether this field supports multiple values. For single-value fields, returns the main form group. For multi-value fields, returns the form group at the active index from the parent FormArray. If no formGroup is set, returns the parent of the formControl.

Gets the currently active form group based on context.

View Source lib/engine/NgxFormFieldDirective.ts, line 270

number

# activeFormGroupIndex

When working with multiple form groups (form arrays), this indicates which form group is currently active or being edited. This is used to manage focus and data binding in multi-entry scenarios.

Index of the currently active form group in a form array.

Default Value:
  • 0

View Source lib/engine/NgxFormFieldDirective.ts, line 67

number

# activeFormGroupIndex

When working with multiple form groups (form arrays), this indicates which form group is currently active or being edited. This is used to manage focus and data binding in multi-entry scenarios.

Index of the currently active form group in a form array.

Default Value:
  • 0

View Source lib/engine/NgxFormFieldDirective.ts, line 510

string

# different

Field name that this field's value must differ from.

Field name that this field's value must differ from.

View Source lib/engine/NgxFormFieldDirective.ts, line 204

string

# different

Field name that this field's value must differ from.

Field name that this field's value must differ from.

View Source lib/engine/NgxFormFieldDirective.ts, line 665

boolean

# disabled

When true, the field cannot be edited by the user.

Whether the field is disabled.

View Source lib/engine/NgxFormFieldDirective.ts, line 123

boolean

# disabled

When true, the field cannot be edited by the user.

Whether the field is disabled.

View Source lib/engine/NgxFormFieldDirective.ts, line 572

string

# equals

Field name that this field's value must equal.

Field name that this field's value must equal.

View Source lib/engine/NgxFormFieldDirective.ts, line 198

string

# equals

Field name that this field's value must equal.

Field name that this field's value must equal.

View Source lib/engine/NgxFormFieldDirective.ts, line 658

FormControl

# formControl

The FormControl that manages this field's value, validation state, and user interactions.

Angular FormControl instance for this field.

View Source lib/engine/NgxFormFieldDirective.ts, line 102

FormControl

# formControl

The FormControl that manages this field's value, validation state, and user interactions.

Angular FormControl instance for this field.

View Source lib/engine/NgxFormFieldDirective.ts, line 548

FormGroup | undefined

# formGroup

The FormGroup that contains this field's FormControl. Used for managing the field's validation state and value within the reactive forms structure.

Angular FormGroup instance for the field.

View Source lib/engine/NgxFormFieldDirective.ts, line 95

FormGroup | undefined

# formGroup

The FormGroup that contains this field's FormControl. Used for managing the field's validation state and value within the reactive forms structure.

Angular FormGroup instance for the field.

View Source lib/engine/NgxFormFieldDirective.ts, line 540

string

# format

Date/time format string for parsing and display.

Date/time format string for parsing and display.

View Source lib/engine/NgxFormFieldDirective.ts, line 137

string

# format

Date/time format string for parsing and display.

Date/time format string for parsing and display.

View Source lib/engine/NgxFormFieldDirective.ts, line 587

string

# greaterThan

Field name that this field's value must be greater than.

Field name that this field's value must be greater than.

View Source lib/engine/NgxFormFieldDirective.ts, line 222

string

# greaterThan

Field name that this field's value must be greater than.

Field name that this field's value must be greater than.

View Source lib/engine/NgxFormFieldDirective.ts, line 686

string

# greaterThanOrEqual

Field name that this field's value must be greater than or equal to.

Field name that this field's value must be greater than or equal to.

View Source lib/engine/NgxFormFieldDirective.ts, line 228

string

# greaterThanOrEqual

Field name that this field's value must be greater than or equal to.

Field name that this field's value must be greater than or equal to.

View Source lib/engine/NgxFormFieldDirective.ts, line 693

boolean | Array.<CrudOperationKeys>

# hidden

Can be a boolean or an array of operation keys where the field should be hidden.

Controls field visibility based on CRUD operations.

View Source lib/engine/NgxFormFieldDirective.ts, line 144

boolean | Array.<CrudOperationKeys>

# hidden

Can be a boolean or an array of operation keys where the field should be hidden.

Controls field visibility based on CRUD operations.

View Source lib/engine/NgxFormFieldDirective.ts, line 595

string

# lessThan

Field name that this field's value must be less than.

Field name that this field's value must be less than.

View Source lib/engine/NgxFormFieldDirective.ts, line 210

string

# lessThan

Field name that this field's value must be less than.

Field name that this field's value must be less than.

View Source lib/engine/NgxFormFieldDirective.ts, line 672

string

# lessThanOrEqual

Field name that this field's value must be less than or equal to.

Field name that this field's value must be less than or equal to.

View Source lib/engine/NgxFormFieldDirective.ts, line 216

string

# lessThanOrEqual

Field name that this field's value must be less than or equal to.

Field name that this field's value must be less than or equal to.

View Source lib/engine/NgxFormFieldDirective.ts, line 679

number | Date

# max

Maximum value or date allowed.

Maximum value or date allowed.

View Source lib/engine/NgxFormFieldDirective.ts, line 150

number | Date

# max

Maximum value or date allowed.

Maximum value or date allowed.

View Source lib/engine/NgxFormFieldDirective.ts, line 602

number

# maxlength

Maximum length for text input.

Maximum length for text input.

View Source lib/engine/NgxFormFieldDirective.ts, line 156

number

# maxlength

Maximum length for text input.

Maximum length for text input.

View Source lib/engine/NgxFormFieldDirective.ts, line 609

number | Date

# min

Minimum value or date allowed.

Minimum value or date allowed.

View Source lib/engine/NgxFormFieldDirective.ts, line 162

number | Date

# min

Minimum value or date allowed.

Minimum value or date allowed.

View Source lib/engine/NgxFormFieldDirective.ts, line 616

number

# minlength

Minimum length for text input.

Minimum length for text input.

View Source lib/engine/NgxFormFieldDirective.ts, line 168

number

# minlength

Minimum length for text input.

Minimum length for text input.

View Source lib/engine/NgxFormFieldDirective.ts, line 623

boolean

# multiple

When true, the field is rendered as part of a FormArray structure.

Whether the field supports multiple values.

View Source lib/engine/NgxFormFieldDirective.ts, line 242

boolean

# multiple

When true, the field is rendered as part of a FormArray structure.

Whether the field supports multiple values.

View Source lib/engine/NgxFormFieldDirective.ts, line 709

function

# onChange

Function registered by Angular's forms system through registerOnChange. Called automatically when the field's value is updated to notify the form of the change.

Callback function invoked when the field value changes.

View Source lib/engine/NgxFormFieldDirective.ts, line 296

function

# onChange

Function registered by Angular's forms system through registerOnChange. Called automatically when the field's value is updated to notify the form of the change.

Callback function invoked when the field value changes.

View Source lib/engine/NgxFormFieldDirective.ts, line 755

function

# onTouch

Function registered by Angular's forms system through registerOnTouched. Called when the field is blurred or otherwise marked as touched.

Callback function invoked when the field is touched.

View Source lib/engine/NgxFormFieldDirective.ts, line 305

function

# onTouch

Function registered by Angular's forms system through registerOnTouched. Called when the field is blurred or otherwise marked as touched.

Callback function invoked when the field is touched.

View Source lib/engine/NgxFormFieldDirective.ts, line 764

KeyValue | FunctionLike

# optionsMapper

Defines how fields from the data model should be mapped to properties used by the component. This allows for flexible data binding between the model and the component's display logic. Can be either a key-value mapping object or a function that performs the mapping.

Field mapping configuration for options.

View Source lib/engine/NgxFormFieldDirective.ts, line 87

KeyValue | FunctionLike

# optionsMapper

Defines how fields from the data model should be mapped to properties used by the component. This allows for flexible data binding between the model and the component's display logic. Can be either a key-value mapping object or a function that performs the mapping.

Field mapping configuration for options.

View Source lib/engine/NgxFormFieldDirective.ts, line 531

number

# page

Indicates which page this field belongs to in a multi-page form structure.

Page number for multi-page forms.

View Source lib/engine/NgxFormFieldDirective.ts, line 130

number

# page

Indicates which page this field belongs to in a multi-page form structure.

Page number for multi-page forms.

View Source lib/engine/NgxFormFieldDirective.ts, line 580

HTMLElement

# protected parent

Used for DOM manipulation and event handling.

Reference to the parent HTML element.

View Source lib/engine/NgxFormFieldDirective.ts, line 256

HTMLElement

# protected parent

Used for DOM manipulation and event handling.

Reference to the parent HTML element.

View Source lib/engine/NgxFormFieldDirective.ts, line 727

FormParent

# parentForm

Reference to the parent FormGroup or FormArray that contains this field. When this field is part of a multi-entry structure, this contains the FormArray with all form groups. This enables management of multiple instances of the same field structure within a single form.

Parent form container for this field.

View Source lib/engine/NgxFormFieldDirective.ts, line 78

FormParent

# parentForm

Reference to the parent FormGroup or FormArray that contains this field. When this field is part of a multi-entry structure, this contains the FormArray with all form groups. This enables management of multiple instances of the same field structure within a single form.

Parent form container for this field.

View Source lib/engine/NgxFormFieldDirective.ts, line 521

string

# path

Used to locate this field within nested form structures.

Dot-separated path to this field in the form structure.

View Source lib/engine/NgxFormFieldDirective.ts, line 109

string

# path

Used to locate this field within nested form structures.

Dot-separated path to this field in the form structure.

View Source lib/engine/NgxFormFieldDirective.ts, line 556

string | undefined

# pattern

Regex pattern for validation.

Regex pattern for validation.

View Source lib/engine/NgxFormFieldDirective.ts, line 174

string | undefined

# pattern

Regex pattern for validation.

Regex pattern for validation.

View Source lib/engine/NgxFormFieldDirective.ts, line 630

boolean

# readonly

Whether the field is read-only.

Whether the field is read-only.

View Source lib/engine/NgxFormFieldDirective.ts, line 180

boolean

# readonly

Whether the field is read-only.

Whether the field is read-only.

View Source lib/engine/NgxFormFieldDirective.ts, line 637

boolean

# required

Whether the field is required.

Whether the field is required.

View Source lib/engine/NgxFormFieldDirective.ts, line 186

boolean

# required

Whether the field is required.

Whether the field is required.

View Source lib/engine/NgxFormFieldDirective.ts, line 644

function

# sf

Provides access to the sf (string format) function for formatting error messages and other string templates. Used primarily for localizing and parameterizing validation messages.

String formatting utility function.

View Source lib/engine/NgxFormFieldDirective.ts, line 287

function

# sf

Provides access to the sf (string format) function for formatting error messages and other string templates. Used primarily for localizing and parameterizing validation messages.

String formatting utility function.

View Source lib/engine/NgxFormFieldDirective.ts, line 746

number

# step

Step value for numeric inputs.

Step value for numeric inputs.

View Source lib/engine/NgxFormFieldDirective.ts, line 192

number

# step

Step value for numeric inputs.

Step value for numeric inputs.

View Source lib/engine/NgxFormFieldDirective.ts, line 651

PossibleInputTypes

# type

Determines the HTML input type or component type to render.

The input type of this field.

View Source lib/engine/NgxFormFieldDirective.ts, line 116

PossibleInputTypes

# type

Determines the HTML input type or component type to render.

The input type of this field.

View Source lib/engine/NgxFormFieldDirective.ts, line 564

string | number | Date | Array.<string>

# value

Can be a string, number, date, or array of strings for multi-select fields.

Current value of the field.

View Source lib/engine/NgxFormFieldDirective.ts, line 235

string | number | Date | Array.<string>

# value

Can be a string, number, date, or array of strings for multi-select fields.

Current value of the field.

View Source lib/engine/NgxFormFieldDirective.ts, line 701

Methods

# activeFormGroup() → {FormGroup}

Returns the appropriate FormGroup based on whether this field supports multiple values. For single-value fields, returns the main form group. For multi-value fields, returns the form group at the active index from the parent FormArray. If no formGroup is set, returns the parent of the formControl.

Gets the currently active form group based on context.

View Source lib/engine/NgxFormFieldDirective.ts, line 738

The currently active FormGroup for this field

FormGroup

# afterViewInit() → {HTMLElement}

Retrieves and returns the parent HTML element based on the current CRUD operation. For READ and DELETE operations, returns the immediate parent element. For CREATE and UPDATE operations, finds the parent div element and registers it with the form service.

Performs setup after the view has been initialized.

View Source lib/engine/NgxFormFieldDirective.ts, line 817

If unable to retrieve parent form element for CREATE/UPDATE operations

RenderingError

If the operation is invalid

InternalError

The parent element of the field

HTMLElement

# getErrors(parent) → {string|void}

Checks the form control for validation errors and returns formatted error messages. If errors exist, dispatches a validation error event to parent accordion components. Error messages are translated and formatted with relevant field properties.

Retrieves validation error messages for the field.

Parameters:
Name Type Description
parent HTMLElement

The parent HTML element used to find accordion components

View Source lib/engine/NgxFormFieldDirective.ts, line 860

Formatted error message string, or void if no errors

string | void

# async ngOnChanges(changes) → {void}

Overrides the parent ngOnChanges to handle changes to activeFormGroupIndex and value. When activeFormGroupIndex changes in a multiple field scenario, updates the active form group and form control. When value changes, updates the form control value. Delegates to parent implementation for initial change detection.

Angular lifecycle hook for detecting input property changes.

Parameters:
Name Type Description
changes SimpleChanges

Object containing the changed properties

View Source lib/engine/NgxFormFieldDirective.ts, line 830

void

# onDestroy() → {void}

Unregisters the form group from the form service to prevent memory leaks and clean up form references.

Cleanup logic when the component is destroyed.

View Source lib/engine/NgxFormFieldDirective.ts, line 839

void

# registerOnChange(fn) → {void}

Part of Angular's ControlValueAccessor interface. Stores the function that Angular forms provides to be called when the field value changes.

Registers the onChange callback function.

Parameters:
Name Type Description
fn function

The function to be called on change

View Source lib/engine/NgxFormFieldDirective.ts, line 785

void

# registerOnTouched(fn) → {void}

Part of Angular's ControlValueAccessor interface. Stores the function that Angular forms provides to be called when the field is touched/blurred.

Registers the onTouched callback function.

Parameters:
Name Type Description
fn function

The function to be called on touch

View Source lib/engine/NgxFormFieldDirective.ts, line 795

void

# setDisabledState(isDisabled) → {void}

Part of Angular's ControlValueAccessor interface. Called by Angular forms when the disabled state of the control changes.

Sets the disabled state of the field.

Parameters:
Name Type Description
isDisabled boolean

Whether the field should be disabled

View Source lib/engine/NgxFormFieldDirective.ts, line 805

void

# setValue(value) → {void}

Updates the form control's value and triggers validation. This is used when the value needs to be programmatically updated from outside the form control.

Sets the value of the form control.

Parameters:
Name Type Description
value unknown

The value to set

View Source lib/engine/NgxFormFieldDirective.ts, line 849

void

# writeValue(obj) → {void}

Part of Angular's ControlValueAccessor interface. Sets the field's value when the form programmatically updates it. This is called by Angular forms when the model value changes.

Writes a value to the form field.

Parameters:
Name Type Description
obj string

The value to be set

View Source lib/engine/NgxFormFieldDirective.ts, line 775

void