signal-template-forms
Version:
A powerful, type-safe Angular forms library built with signals, providing reactive form management with excellent developer experience and performance.
128 lines (127 loc) • 4.52 kB
TypeScript
import { OnInit } from '@angular/core';
import { FormFieldType } from '../enums/form-field-type.enum';
import { type SignalFormField } from '../models/signal-form.model';
import * as i0 from "@angular/core";
/**
* Signal-based form field directive that handles two-way data binding, validation,
* and accessibility attributes for form elements
*
* @template TModel - The form model type
* @template K - The field key type
* @template TFieldType - The form field type enum
*/
export declare class SignalModelDirective<TModel extends object, K extends keyof TModel = keyof TModel, TFieldType extends FormFieldType = FormFieldType> implements OnInit {
signalModel: import("@angular/core").InputSignal<SignalFormField<TModel, K>>;
private initialValue;
private hasCapturedInitial;
private roleAttributes;
private readonly elementRef;
private readonly renderer;
private readonly injector;
private readonly roleService;
private readonly validationService;
private form;
/**
* Binds the field name as the element's name attribute
* @returns The field name as a string
*/
get name(): string;
/**
* Binds the field name as the element's id attribute
* @returns The field name as a string
*/
get id(): string;
/**
* Generates a unique ID for radio buttons by checking existing IDs in the DOM
*/
private generateUniqueRadioId;
/**
* Initializes the directive by setting up all reactive effects
*/
constructor();
/**
* Angular lifecycle hook that sets the initial element value
*/
ngOnInit(): void;
/**
* Sets up effect to capture the initial field value for dirty state tracking
*/
private setupInitialValueEffect;
/**
* Sets up effect to handle focus highlighting behavior and auto-focus
*/
private setupFocusEffect;
/**
* Sets up effect to sync element value with model value changes
*/
private setupValueSyncEffect;
/**
* Sets up effect to dynamically apply all field attributes (role, aria, input)
*/
private setupAttributesEffect;
/**
* Sets the initial element value from the field model
*/
private setInitialValue;
/**
* Extracts the field value as a display string
* @returns The field value formatted as a string, or null if no value
*/
private getFieldValue;
/**
* Handles blur events by marking the field as touched and triggering blur validation
*/
onBlur(): void;
/**
* Handles focus events by updating the field focus state
*/
onFocus(): void;
/**
* Handles input events and updates the model value with parsed data
*/
onInput(event: Event): void;
/**
* Extracts the raw value from different types of form elements
* @param target - The form element to extract value from
* @returns The extracted value based on element type
*/
private extractValue;
/**
* Sets the value of a form element based on its type
* @param element - The form element to update
* @param value - The value to set
*/
private setElementValue;
/**
* Sets the checked state of a checkbox input
* @param element - The checkbox input element
* @param value - The boolean value to set
*/
private setCheckboxValue;
/**
* Sets the date value of a date input
* @param element - The date input element
* @param value - The Date object to set
*/
private setDateValue;
/**
* Sets the numeric value of a number input
* @param element - The number input element
* @param value - The number value to set
*/
private setNumberValue;
/**
* Sets the string value of standard form elements
* @param element - The form element (input, select, textarea)
* @param value - The value to convert to string and set
*/
private setStandardValue;
/**
* Sets accessibility attributes for custom combobox elements
* @param element - The div element with combobox role
* @param value - The value to set as aria-valuenow
*/
private setComboboxValue;
static ɵfac: i0.ɵɵFactoryDeclaration<SignalModelDirective<any, any, any>, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<SignalModelDirective<any, any, any>, "[signalModel]", never, { "signalModel": { "alias": "signalModel"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
}