import * as i10 from '@angular/forms'; import { FormGroup, ValidationErrors, ValidatorFn, AbstractControl, Validator, ControlValueAccessor, FormControl } from '@angular/forms'; import { TbxModelMetadata, TbxError, TbxMetadata } from '@lacera/ngx-toolbox/http'; import { TbxBaseComponent } from '@lacera/ngx-toolbox/components'; import * as i0 from '@angular/core'; import { OnInit, OnChanges, SimpleChanges, ElementRef, AfterContentInit, OnDestroy, Injector } from '@angular/core'; import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot, MaybeAsync, GuardResult } from '@angular/router'; import * as i9 from '@angular/common'; /** * Defines the interface that components must implement to let Angular know * whether they can be deactivated. Use {@link canDeactivate} in the routes. */ interface TbxCanDeactivate { /** Checks if the component implements canDeactivate and calls it, otherwise * it returns true to deactivate. * @returns true if it can deactivate, false otherwise. */ get canDeactivate(): boolean; } /** * Displays error messages for the specified control. */ declare abstract class TbxBaseFormComponent extends TbxBaseComponent implements TbxCanDeactivate { /** Stores the form for the view. */ form: FormGroup; /** Gets or sets a value indicating whether we're in edit mode. */ editMode: boolean; /** * Let Angular know whether the user can navigate away from this component. * @see TbxCanDeactivateGuard * @returns true if navigation allowed, false otherwise. */ get canDeactivate(): boolean; /** * Gets the Bootstrap CSS classes to show errors for when a field is invalid. * @param fieldName The field to validate. * @returns The CSS classes. */ getFieldErrorCss(fieldName: string): {}; /** * Checks if a field is valid by checking the control's Valid value and whether * the control has been touched. * @param fieldName - The field to check. * @returns true if valid, false otherwise. */ isFieldValid(fieldName: string): boolean; /** * Validates the form and if not valid, it displays a message to the user. * @param theForm The form to validate. * @returns true if the form is valid, false otherwise. */ isFormValid(theForm?: FormGroup): boolean; /** * Validates all fields in the specified form, and causes validation messages. * @returns The list of errors found in the fields, if any. */ validateAllFields(): string[]; /** * Creates the form based on the specified model (received from the back-end). * @param model The model received from the server. * @param dateFormat The format for the dates if requested as string. * @param convertDates Indicates to convert the values to {@link Date} * or leave as received/string. * @throws The model must be provided. */ createForm(model: TbxModelMetadata, dateFormat?: string, convertDates?: boolean): void; /** * A shortcut to sets errors on a form control when running validations manually * instead of having to get the control and validate. * @param field The name of the field to set in the form. * @param errors The map of errors to set for the field control. * @throws The field does not exist in the local form or the specified one. * @returns Nothing. */ setFieldErrors(field: string, errors: ValidationErrors | null): void; /** * Handles errors encountered while saving a record in the form. * @param error The error received from the service. * @param theForm The optional form to validate. * @returns Nothing. */ handleSaveError(error: TbxError, theForm?: FormGroup): void; /** * Adds a new control to the current form. * @param name The name of the field that matches 'fieldControlName' in the form. * @param value The initial value of the control. * @param validators The validators to add to the form control. * @param messages The messages to add to the {@link TbxValidationComponent} control. * @returns The control added to the form. */ addFormField(name: string, value: any, validators?: ValidatorFn[], messages?: any): AbstractControl; /** * Adds additional validators to the given control name and its messages. * @param name The name of the field that matches 'fieldControlName' in the form. * @param validators The validators to add to the form control. * @param messages The messages to add to the {@link TbxValidationComponent} control. * @returns The form control that was modified. */ addFormFieldValidators(name: string, validators: ValidatorFn[], messages?: any): AbstractControl; private static ensureFormObject; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Displays error messages for the specified control. */ declare class TbxValidationComponent { /** Gets or sets the control for which to check for errors. */ readonly control: i0.InputSignal | null | undefined>; /** Gets or sets an optional message to display when there is an error. */ readonly message: i0.InputSignal; /** Gets the error message for the control, or null if none. */ get errorMessage(): string | null; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵcmp: i0.ɵɵComponentDeclaration; } /** Defines the type of validation codes that can be looked up. */ type TbxValidationCode = "required" | "minlength" | "maxlength" | "max" | "min" | "invalidCreditCard" | "invalidEmailAddress" | "invalidDate" | "invalidSSN" | "invalidNumber" | "invalidCurrency" | "equal" | "notEqual"; /** Defines the interface for a validation message. */ interface TbxValidationMessage { [key: string]: string; } /** Defines the interface for a validation messages for a form control. */ interface TbxValidationControlMessages { [key: string]: TbxValidationMessage[]; } /** Defines the interface for a validation messages for a form. */ interface TbxValidationFormMessages { [key: string]: TbxValidationControlMessages[]; } /** * Gets the control name by querying the parent of the control. * @param control The control for which to get the name. * @exception control must be provided to the function. * @returns The control name or undefined */ declare const getControlName: (control?: AbstractControl) => string | undefined; /** * Gets the Bootstrap CSS classes to show errors for when a field is invalid. * @param fieldName The field to validate. * @param form The form that contains the field. * @param className The class name to apply to the control (defaults to 'is-invalid'). * @returns The CSS classes. */ declare const getFieldErrorCss: (fieldName: string, form: FormGroup, className?: string) => {}; /** * A shortcut to sets errors on a form control when running validations manually * instead of having to get the control and validate. * @param field The name of the field to set in the form. * @param errors The map of errors to set for the field control. * @param form The form to search for the field. If not specified, * the local form is searched. * @throws The field does not exist in the local form or the specified one. * @returns Nothing. */ declare const setFieldErrors: (field: string, errors: ValidationErrors | null, form: FormGroup) => void; /** * Checks if a field is valid by checking the control's Valid value and whether * the control has been touched. * @param fieldName The field to check. * @param form The form that contains the control. * @returns true if valid, false otherwise. */ declare const isFieldValid: (fieldName: string, form: FormGroup) => boolean; /** * Validates all fields in the specified form, and causes validation messages. * @param form The form to validate. * @returns The list of errors found in the fields, if any. */ declare const validateAllFields: (form: FormGroup) => string[]; /** * Determines if the given data type is a C# numeric type such as Int32, * Int32?, int, or int?. * @param type The C# data type to check. * @returns true if the data type is numeric, false otherwise. */ declare const isNumberDataType: (type: string | null) => boolean; /** * Determines if the given data type is a C# date type such as DateTime, * DateTime?, Date, or Date?. * @param type The C# data type to check. * @returns true if the data type is a DateTime, false otherwise. */ declare const isDateDataType: (type: string | null) => boolean; /** * Determines if the given data type is a C# float type such as Decimal, * Decimal?, Double, or Double?. * @param type The C# data type to check. * @returns true if the data type is numeric, false otherwise. */ declare const isFloatDateType: (type: string | null) => boolean; /** * Creates the form based on the specified model (received from the back-end). * @param model The model received from the server. * @param dateFormat The format for the dates if requested as string. * @param convertDates Indicates to convert the values to {@link Date} * @throws The model must be provided. */ declare const createReactiveForm: (model: TbxModelMetadata, dateFormat?: string, convertDates?: boolean) => FormGroup; declare const getValidatorsFromMeta: (meta: TbxMetadata) => { /** The validators for the form. */ validators: ValidatorFn[]; /** The validation messages to display on violations. */ messages: TbxValidationMessage[]; }; /** * Directive that requires a control value to be equal to a specified value. */ declare class TbxEqualValidator implements Validator, OnInit, OnChanges { /** Gets or sets the value the control value should equal to. */ equal: any; /** Stores the validator function called when the control value changes. */ private validator; /** Stores the function to call when value changes. */ private onChange; /** * Invoked only once when the directive is instantiated. */ ngOnInit(): void; /** * Called when the content has changed. * @param changes Contains the changed properties. */ ngOnChanges(changes: SimpleChanges): void; /** * Called to validate the specified control value. * @param c The control to validate. * @returns The validation errors or null if validation succeeds. */ validate(c: AbstractControl): ValidationErrors | null; /** * Called when the validator is changed. * @param fn The function to be called when the validator changes. */ registerOnValidatorChange(fn: () => void): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } /** * Directive that requires a control value to be equal to a specified value. */ declare class TbxNotEqualValidator implements Validator, OnInit, OnChanges { /** Gets or sets the value the control value should not equal to. */ equal: any; /** Stores the validator function called when the control value changes. */ private validator; /** Stores the function to call when value changes. */ private onChange; ngOnInit(): void; ngOnChanges(changes: SimpleChanges): void; /** * Called to validate the specified control value. * @param c The control to validate. * @returns The validation errors or null if validation succeeds. */ validate(c: AbstractControl): ValidationErrors | null; /** * Called when the validator is changed. * @param fn The function to be called when the validator changes. */ registerOnValidatorChange(fn: () => void): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } /** * Directive that requires a control value to be of currency format ($0.00). */ declare class TbxCurrencyValidator implements Validator { /** Indicates whether the validator is enabled. */ private enabled; /** Stores the function to call when value changes. */ private onChange; /** * Sets the currency value when it changes. * @param value The changed value. */ set currency(value: boolean | string); /** * Called to validate the specified control value. * @param c The control to validate. * @returns The validation errors or null if validation succeeds. */ validate(c: AbstractControl): ValidationErrors | null; /** * Called when the validator is changed. * @param fn The function to be called when the validator changes. */ registerOnValidatorChange(fn: () => void): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } /** * Directive that requires a control value to be uppercase. */ declare class TbxUpperDirective { ref: ElementRef; private inputEl?; constructor(ref: ElementRef); onInput(_: any): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } /** * Provides form validation services to be shared in the application. */ declare class TbxValidationService { /** * The messages for a form that are provided when the form is instantiated. These * are used instead of the standard message for the various validators. */ static formMessages: TbxValidationControlMessages[]; /** * Gets the validation error message for the specified code. * @param code The validator code. * @param validatorValue The validator value. * @param controlName The name of the control. * @returns The validator error message if found. */ static getValidatorErrorMessage(code: string, validatorValue: any, controlName?: string): string | null; /** * Gets the message if controlName is specified, and form control messages * have been provided. * @param code The validator code. * @param controlName The control name to find. * @returns The control message if found, null otherwise. */ static getControlMessage(code: string, controlName?: string): string | null; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Validator that requires a date. It uses {@link isDateValid}, which checks if * the date is of types {@link Date} or {@link String} ignoring numbers. * @param control The control to validate. * @returns 'invalidDate' as true if validation fails, otherwise null. */ declare const dateValidator: (control: AbstractControl) => ValidationErrors | null; /** * Validator that requires a social security number with or without dashes. * @param control The control to validate. * @returns 'invalidSSN' as true if validation fails, otherwise null. */ declare const ssnValidator: (control: AbstractControl) => ValidationErrors | null; /** * Validator that performs validation on an Internet email address (SMTP). It * uses an RFC 2822 compliant regex match. * @param control The control to validate. * @returns 'invalidEmailAddress' as true if validation fails, otherwise null. */ declare const emailValidator: (control: AbstractControl) => ValidationErrors | null; /** * Validator that performs validation on a credit card number * (Visa, MasterCard, American Express, Diners Club, Discover, and JCB). * @param control The control to validate. * @returns 'invalidCreditCard' as true if validation fails, otherwise null. */ declare const creditCardValidator: (control: AbstractControl) => ValidationErrors | null; /** * Validator that requires the control value to be equal to a specified value. * @param value The value the compare against. * @returns 'equal' as true if validation fails, otherwise null. */ declare const equalValidator: (value: any) => ValidatorFn; /** * Validator that requires the control value to not be equal to a specified value. * @param value The value the compare against. * @returns 'notEqual' as true if validation fails, otherwise null. */ declare const notEqualValidator: (value: any) => ValidatorFn; /** * Validator that requires the control value to be a number. * @param control The control to validate. * @returns 'invalidNumber' as false if validation fails, otherwise null. */ declare const numericValidator: (control: AbstractControl) => ValidationErrors | null; /** * Validator that requires the control value to be of currency format ($0.00). * @param control The control to validate. * @returns 'invalidCurrency' as false if validation fails, otherwise null. */ declare const currencyValidator: (control: AbstractControl) => ValidationErrors | null; /** * Directive sets the focus on an element. */ declare class TbxAutofocusDirective implements AfterContentInit, OnChanges, OnDestroy { private readonly elementRef; /** Indicates whether to focus the element. */ shouldFocusElement: i0.InputSignal; /** The delay before taking the focus. */ timerDelay: i0.ModelSignal; /** The timer to know when to focus. */ private timer?; /** * Initializes a new instance of the {@link TbxAutofocusDirective} class. * @param elementRef The element to set the focus to. */ constructor(elementRef: ElementRef); /** Called once after the contents have been fully initialized. */ ngAfterContentInit(): void; /** * Called every time the input bindings are updated. * @param changes The changes that cause the update. */ ngOnChanges(changes: SimpleChanges): void; /** Called when the directive is destroyed. */ ngOnDestroy(): void; private startFocusWorkflow; private stopFocusWorkflow; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } /** * Determines if a component can be deactivated. It calls the component's * implementation of the {@link TbxCanDeactivate} interface. */ declare const tbxCanDeactivateFn: (component: TbxCanDeactivate) => boolean; /** * Determines if a component can be deactivated. It calls the component's * implementation of the {@link canDeactivate} function. */ declare class TbxCanDeactivateGuard implements CanDeactivate { canDeactivate(component: TbxCanDeactivate, _currentRoute: ActivatedRouteSnapshot, _currentState: RouterStateSnapshot, _nextState: RouterStateSnapshot): MaybeAsync; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } declare class TbxAccessorBaseDirective implements OnInit, OnDestroy, ControlValueAccessor { private readonly injector; required: i0.InputSignal; requiredValue: i0.WritableSignal; formControl: FormControl; disabled: boolean; onTouched: () => void; onChange: (val: T | null) => T; private changeSub?; constructor(injector: Injector); ngOnInit(): void; ngOnDestroy(): void; registerOnChange(fn: (val: T | null) => T): void; writeValue(value: T): void; registerOnTouched(fn: () => void): void; setDisabledState?(isDisabled: boolean): void; private setFormControl; static ɵfac: i0.ɵɵFactoryDeclaration, never>; static ɵdir: i0.ɵɵDirectiveDeclaration, "[tbxControlValueAccessor]", never, { "required": { "alias": "required"; "required": false; "isSignal": true; }; }, {}, never, never, false, never>; } declare class TbxInputBaseDirective extends TbxAccessorBaseDirective { /** * The input ID (usually the form control name. This input is used * for the {@link formControlName}, the ID of the HTML element and the "for" * attribute of the label. */ inputId: i0.InputSignal; /** * The control name for a reactive form control. */ formControlName: i0.InputSignal; /** * The label caption to display on the control. If left blank, the label * will not be displayed. */ label: i0.InputSignal; /** * Any additional classes to add to the div that contains the label, input, * and validation message controls. */ class: i0.InputSignal; /** * Any additional classes to add to the Input element (defaults to form-control). */ inputClass: i0.InputSignal; /** * The error message to display when the control is invalid. If left blank, * the default message will be used such as required message. */ errorMessage: i0.InputSignal; /** * Indicates to show the validation error messages (defaults to show). */ showValidationErrors: i0.InputSignal; /** * Indicates whether the control is read-only (defaults to false). */ readonly: i0.InputSignal; /** * The text to display in the input element as a placeholder. */ placeholder: i0.InputSignal; /** * The data list to attach to the input element. */ dataList: i0.InputSignal; get internalClass(): string; static ɵfac: i0.ɵɵFactoryDeclaration, never>; static ɵdir: i0.ɵɵDirectiveDeclaration, "[tbxInputBaseDirective]", never, { "inputId": { "alias": "inputId"; "required": true; "isSignal": true; }; "formControlName": { "alias": "formControlName"; "required": true; "isSignal": true; }; "label": { "alias": "label"; "required": false; "isSignal": true; }; "class": { "alias": "class"; "required": false; "isSignal": true; }; "inputClass": { "alias": "inputClass"; "required": false; "isSignal": true; }; "errorMessage": { "alias": "errorMessage"; "required": false; "isSignal": true; }; "showValidationErrors": { "alias": "showValidationErrors"; "required": false; "isSignal": true; }; "readonly": { "alias": "readonly"; "required": false; "isSignal": true; }; "placeholder": { "alias": "placeholder"; "required": false; "isSignal": true; }; "dataList": { "alias": "dataList"; "required": false; "isSignal": true; }; }, {}, never, never, false, never>; } declare class TbxFormActionsComponent { /** The type of button Save is (defaults to 'submit'). */ saveButtonType: i0.InputSignal; /** The text to display in the save button. */ saveText: i0.InputSignal; /** Indicates to show or hide the Cancel button. */ showCancel: i0.InputSignal; /** Indicates to disable the controls. */ disabled: i0.InputSignal; saveClick: i0.OutputEmitterRef; cancelClick: i0.OutputEmitterRef; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵcmp: i0.ɵɵComponentDeclaration; } declare class TbxInputComponent extends TbxInputBaseDirective { /** * The type of input HTML element to set such as text, phone, password, * date, time, image, color, etc. (defaults to 'text'). */ type: i0.InputSignal; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵcmp: i0.ɵɵComponentDeclaration; } declare class TbxLabelComponent extends TbxAccessorBaseDirective { /** * The input ID (usually the form control name. This input is used * for the {@link formControlName}, the ID of the HTML element and the "for" * attribute of the label. */ inputId: i0.InputSignal; /** * The label caption to display on the control. If left blank, the label * will not be displayed. */ label: i0.InputSignal; /** * Any additional classes to add to the Input element (defaults to form-control). */ inputClass: i0.InputSignal; get internalClass(): string; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵcmp: i0.ɵɵComponentDeclaration; } declare class TbxSelectComponent extends TbxInputBaseDirective { static ɵfac: i0.ɵɵFactoryDeclaration; static ɵcmp: i0.ɵɵComponentDeclaration; } declare class TbxSwitchComponent extends TbxInputBaseDirective { static ɵfac: i0.ɵɵFactoryDeclaration; static ɵcmp: i0.ɵɵComponentDeclaration; } declare class TbxTextAreaComponent extends TbxInputBaseDirective { /** * The number of rows to display in the text-area component. */ rows: i0.InputSignal; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵcmp: i0.ɵɵComponentDeclaration; } declare class TbxFormsModule { static ɵfac: i0.ɵɵFactoryDeclaration; static ɵmod: i0.ɵɵNgModuleDeclaration; static ɵinj: i0.ɵɵInjectorDeclaration; } export { TbxAccessorBaseDirective, TbxAutofocusDirective, TbxBaseFormComponent, TbxCanDeactivateGuard, TbxCurrencyValidator, TbxEqualValidator, TbxFormActionsComponent, TbxFormsModule, TbxInputBaseDirective, TbxInputComponent, TbxLabelComponent, TbxNotEqualValidator, TbxSelectComponent, TbxSwitchComponent, TbxTextAreaComponent, TbxUpperDirective, TbxValidationComponent, TbxValidationService, createReactiveForm, creditCardValidator, currencyValidator, dateValidator, emailValidator, equalValidator, getControlName, getFieldErrorCss, getValidatorsFromMeta, isDateDataType, isFieldValid, isFloatDateType, isNumberDataType, notEqualValidator, numericValidator, setFieldErrors, ssnValidator, tbxCanDeactivateFn, validateAllFields }; export type { TbxCanDeactivate, TbxValidationCode, TbxValidationControlMessages, TbxValidationFormMessages, TbxValidationMessage };