UNPKG

ngx-form-lib

Version:

Dynamic form library for Angular 18 with Material 3 support. Create complex reactive forms easily using JSON configuration with modern Angular 18 control flow syntax.

21 lines 10.9 kB
import { Component } from '@angular/core'; import { BaseComponent } from '../../core/components/base/base.component'; import * as i0 from "@angular/core"; import * as i1 from "@angular/material/form-field"; import * as i2 from "../../shared/components/prefix-suffix/prefix-suffix.component"; import * as i3 from "@angular/forms"; import * as i4 from "@angular/material/input"; import * as i5 from "../../shared/pipes/set-parent-config/set-parent-config.pipe"; export class TextareaComponent extends BaseComponent { constructor() { super(...arguments); this.config = null; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TextareaComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.13", type: TextareaComponent, selector: "ngf-textarea", usesInheritance: true, ngImport: i0, template: "@if (config && group) {\r\n<div [formGroup]=\"group\" class=\"ngf-wrapper ngf-textarea-wrapper\">\r\n <mat-form-field\r\n class=\"ngf-form-field\"\r\n [appearance]=\"parentConfig | setParentConfig : config : 'appearance'\"\r\n [color]=\"parentConfig | setParentConfig : config : 'color'\"\r\n >\r\n <mat-label [attr.for]=\"config.name\">{{ config.label }}</mat-label>\r\n <textarea\r\n matInput\r\n class=\"form-control\"\r\n [formControlName]=\"config.name\"\r\n [id]=\"config.name\"\r\n [placeholder]=\"config.placeholder\"\r\n [rows]=\"config.rows\"\r\n ></textarea>\r\n @if (config.hint) {\r\n <mat-hint>{{ config.hint }}</mat-hint>\r\n } @if (config.prefix) {\r\n <span matPrefix>\r\n <ngf-prefix-suffix [config]=\"config.prefix\"></ngf-prefix-suffix>\r\n </span>\r\n } @if (config.suffix) {\r\n <span matSuffix>\r\n <ngf-prefix-suffix [config]=\"config.suffix\"></ngf-prefix-suffix>\r\n </span>\r\n }\r\n <!-- TODO: Try moving mat-error to a component and implement dynamic error message -->\r\n @for (validationItem of config.validators; track validationItem.type) {\r\n <mat-error class=\"ngf-field-error\">\r\n @if (group.controls[config.name].hasError(validationItem.type) &&\r\n (group.controls[config.name].dirty ||\r\n group.controls[config.name].touched)) {\r\n <span>{{ validationItem.message }}</span>\r\n @if (validationItem.showDynamicError &&\r\n this.group.controls[config.name].getError(validationItem.type)?.actualLength;\r\n as actualLength) {\r\n <span>\r\n {{ actualLength }}/\r\n {{\r\n this.group.controls[config.name].getError(validationItem.type)\r\n ?.requiredLength\r\n }}\r\n </span>\r\n } }\r\n </mat-error>\r\n }\r\n </mat-form-field>\r\n</div>\r\n}\r\n", dependencies: [{ kind: "component", type: i1.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i1.MatLabel, selector: "mat-label" }, { kind: "directive", type: i1.MatHint, selector: "mat-hint", inputs: ["align", "id"] }, { kind: "directive", type: i1.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "directive", type: i1.MatPrefix, selector: "[matPrefix], [matIconPrefix], [matTextPrefix]", inputs: ["matTextPrefix"] }, { kind: "directive", type: i1.MatSuffix, selector: "[matSuffix], [matIconSuffix], [matTextSuffix]", inputs: ["matTextSuffix"] }, { kind: "component", type: i2.PrefixSuffixComponent, selector: "ngf-prefix-suffix", inputs: ["config"] }, { kind: "directive", type: i3.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i3.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i3.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "directive", type: i4.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "pipe", type: i5.SetParentConfigPipe, name: "setParentConfig" }] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: TextareaComponent, decorators: [{ type: Component, args: [{ selector: 'ngf-textarea', template: "@if (config && group) {\r\n<div [formGroup]=\"group\" class=\"ngf-wrapper ngf-textarea-wrapper\">\r\n <mat-form-field\r\n class=\"ngf-form-field\"\r\n [appearance]=\"parentConfig | setParentConfig : config : 'appearance'\"\r\n [color]=\"parentConfig | setParentConfig : config : 'color'\"\r\n >\r\n <mat-label [attr.for]=\"config.name\">{{ config.label }}</mat-label>\r\n <textarea\r\n matInput\r\n class=\"form-control\"\r\n [formControlName]=\"config.name\"\r\n [id]=\"config.name\"\r\n [placeholder]=\"config.placeholder\"\r\n [rows]=\"config.rows\"\r\n ></textarea>\r\n @if (config.hint) {\r\n <mat-hint>{{ config.hint }}</mat-hint>\r\n } @if (config.prefix) {\r\n <span matPrefix>\r\n <ngf-prefix-suffix [config]=\"config.prefix\"></ngf-prefix-suffix>\r\n </span>\r\n } @if (config.suffix) {\r\n <span matSuffix>\r\n <ngf-prefix-suffix [config]=\"config.suffix\"></ngf-prefix-suffix>\r\n </span>\r\n }\r\n <!-- TODO: Try moving mat-error to a component and implement dynamic error message -->\r\n @for (validationItem of config.validators; track validationItem.type) {\r\n <mat-error class=\"ngf-field-error\">\r\n @if (group.controls[config.name].hasError(validationItem.type) &&\r\n (group.controls[config.name].dirty ||\r\n group.controls[config.name].touched)) {\r\n <span>{{ validationItem.message }}</span>\r\n @if (validationItem.showDynamicError &&\r\n this.group.controls[config.name].getError(validationItem.type)?.actualLength;\r\n as actualLength) {\r\n <span>\r\n {{ actualLength }}/\r\n {{\r\n this.group.controls[config.name].getError(validationItem.type)\r\n ?.requiredLength\r\n }}\r\n </span>\r\n } }\r\n </mat-error>\r\n }\r\n </mat-form-field>\r\n</div>\r\n}\r\n" }] }] }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGV4dGFyZWEuY29tcG9uZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vcHJvamVjdHMvbmd4LWZvcm0tbGliL3NyYy9saWIvZmVhdHVyZXMvdGV4dGFyZWEvdGV4dGFyZWEuY29tcG9uZW50LnRzIiwiLi4vLi4vLi4vLi4vLi4vLi4vcHJvamVjdHMvbmd4LWZvcm0tbGliL3NyYy9saWIvZmVhdHVyZXMvdGV4dGFyZWEvdGV4dGFyZWEuY29tcG9uZW50Lmh0bWwiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFNBQVMsRUFBRSxNQUFNLGVBQWUsQ0FBQztBQUUxQyxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sMkNBQTJDLENBQUM7Ozs7Ozs7QUFPMUUsTUFBTSxPQUFPLGlCQUFrQixTQUFRLGFBQXFCO0lBSjVEOztRQUtXLFdBQU0sR0FBb0IsSUFBSSxDQUFDO0tBQ3pDOytHQUZZLGlCQUFpQjttR0FBakIsaUJBQWlCLDJFQ1Q5QiwyMURBa0RBOzs0RkR6Q2EsaUJBQWlCO2tCQUo3QixTQUFTOytCQUNFLGNBQWMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBDb21wb25lbnQgfSBmcm9tICdAYW5ndWxhci9jb3JlJztcclxuXHJcbmltcG9ydCB7IEJhc2VDb21wb25lbnQgfSBmcm9tICcuLi8uLi9jb3JlL2NvbXBvbmVudHMvYmFz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