UNPKG

ngx-surveys

Version:
44 lines 11.4 kB
import { Component, Input, Output, EventEmitter } from '@angular/core'; import { FormItem, SurveyErrorStateMatcher } from '../index'; import * as i0 from "@angular/core"; import * as i1 from "@angular/common"; import * as i2 from "@angular/forms"; import * as i3 from "@angular/material/input"; import * as i4 from "@angular/material/form-field"; export class FormItemString extends FormItem { } export class FormItemStringComponent { constructor() { this.editable = true; this.changes = new EventEmitter(); this.matcher = new SurveyErrorStateMatcher(); this.maxLabelLength = 60; } ngOnInit() { this.matcher.item = this.item; } ngOnChanges() { this.matcher.item = this.item; } checkRequired(placeholder) { if (placeholder === 'Required') { return true; } } onValueChanges(item) { this.changes.emit(item); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: FormItemStringComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.12", type: FormItemStringComponent, selector: "ammo-form-item-string", inputs: { item: "item", editable: "editable" }, outputs: { changes: "changes" }, usesOnChanges: true, ngImport: i0, template: "\n<mat-form-field>\n <label class=\"long-label-text\" *ngIf=\"item.label.length>=maxLabelLength\" [ngClass]=\"{'has-error':item.errors && item.errors.length}\">{{item.label}} <span *ngIf=\"item.required\" class=\"required-asterix\">*</span></label>\n <input #inputField\n matInput\n [type]=\"item.style || 'text'\"\n [disabled]=\"!editable\"\n [attr.id]=\"item.name\"\n [placeholder]=\"item.label.length<maxLabelLength ? item.label : ''\"\n [(ngModel)]=\"item.value\"\n [minlength]=\"item.fieldValidation ? item.fieldValidation.minLength : undefined \"\n (ngModelChange)=\"onValueChanges(item)\"\n [errorStateMatcher]=\"matcher\"\n [required]=\"item.required\"\n >\n <mat-error *ngIf=\"item.errors && item.errors.length\">\n <div *ngFor=\"let error of item.errors\">{{error.message}}</div>\n </mat-error>\n <mat-hint align=\"start\" *ngIf=\"!(item.errors && item.errors.length) && item.hint?.length < maxLabelLength\"><strong>{{item.hint}}</strong> </mat-hint>\n\n</mat-form-field>\n<small class=\"long-hint\" *ngIf=\"!(item.errors && item.errors.length) && item.hint?.length >= maxLabelLength\"><strong>{{item.hint}}</strong> </small>\n\n", styles: [".mat-mdc-form-field{display:block}.long-label-text{margin-bottom:5px;display:block}.long-hint{margin-top:-14px;display:inline-block;margin-bottom:10px;color:#0000008a;font-size:75%}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.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: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i2.MinLengthValidator, selector: "[minlength][formControlName],[minlength][formControl],[minlength][ngModel]", inputs: ["minlength"] }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i3.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: "component", type: i4.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i4.MatHint, selector: "mat-hint", inputs: ["align", "id"] }, { kind: "directive", type: i4.MatError, selector: "mat-error, [matError]", inputs: ["id"] }] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: FormItemStringComponent, decorators: [{ type: Component, args: [{ selector: 'ammo-form-item-string', template: "\n<mat-form-field>\n <label class=\"long-label-text\" *ngIf=\"item.label.length>=maxLabelLength\" [ngClass]=\"{'has-error':item.errors && item.errors.length}\">{{item.label}} <span *ngIf=\"item.required\" class=\"required-asterix\">*</span></label>\n <input #inputField\n matInput\n [type]=\"item.style || 'text'\"\n [disabled]=\"!editable\"\n [attr.id]=\"item.name\"\n [placeholder]=\"item.label.length<maxLabelLength ? item.label : ''\"\n [(ngModel)]=\"item.value\"\n [minlength]=\"item.fieldValidation ? item.fieldValidation.minLength : undefined \"\n (ngModelChange)=\"onValueChanges(item)\"\n [errorStateMatcher]=\"matcher\"\n [required]=\"item.required\"\n >\n <mat-error *ngIf=\"item.errors && item.errors.length\">\n <div *ngFor=\"let error of item.errors\">{{error.message}}</div>\n </mat-error>\n <mat-hint align=\"start\" *ngIf=\"!(item.errors && item.errors.length) && item.hint?.length < maxLabelLength\"><strong>{{item.hint}}</strong> </mat-hint>\n\n</mat-form-field>\n<small class=\"long-hint\" *ngIf=\"!(item.errors && item.errors.length) && item.hint?.length >= maxLabelLength\"><strong>{{item.hint}}</strong> </small>\n\n", styles: [".mat-mdc-form-field{display:block}.long-label-text{margin-bottom:5px;display:block}.long-hint{margin-top:-14px;display:inline-block;margin-bottom:10px;color:#0000008a;font-size:75%}\n"] }] }], ctorParameters: () => [], propDecorators: { item: [{ type: Input }], editable: [{ type: Input }], changes: [{ type: Output }] } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9ybS1pdGVtLXN0cmluZy5jb21wb25lbnQuanMiLCJzb3VyY2VSb290IjoiIi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