UNPKG

ngx-form-validator

Version:

A library for form validator specifically for Angular 2+ Usage for Reactive Forms

99 lines (93 loc) 4.32 kB
import { Subject } from 'rxjs/index'; import { takeUntil } from 'rxjs/internal/operators'; import '@angular/forms'; import { Component, Input, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgxFormValidatorComponent = /** @class */ (function () { function NgxFormValidatorComponent() { this.destroy$ = new Subject(); } /** * @return {?} */ NgxFormValidatorComponent.prototype.ngOnInit = /** * @return {?} */ function () { this.initControl(); }; /** * @return {?} */ NgxFormValidatorComponent.prototype.initControl = /** * @return {?} */ function () { var _this = this; this.control.statusChanges .pipe(takeUntil(this.destroy$)) .subscribe(function (newValue) { _this.error = _this.control.errors ? window['Object'].keys(_this.control.errors)[0] : null; }); this.error = this.control.errors ? window['Object'].keys(this.control.errors)[0] : null; }; /** * @return {?} */ NgxFormValidatorComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { this.destroy$.next(true); this.destroy$.unsubscribe(); }; NgxFormValidatorComponent.decorators = [ { type: Component, args: [{ selector: 'ngx-form-validator', template: "\n <div *ngIf=\"control?.invalid && control?.touched\"\n class=\"alert-text\"\n >\n <div [ngSwitch]=\"error\">\n <div *ngSwitchCase=\"'required'\"><div>Required field</div></div>\n <div *ngSwitchCase=\"'maxlength'\">\n <div\n *ngIf=\"control.errors.maxlength.requiredLength; else maxLength_zero\"\n >\n Must contain from 1 to\n {{ control.errors.maxlength.requiredLength }} symbols\n </div>\n <ng-template #maxLength_zero>\n Must contain at least\n {{ control.errors.maxlength.requiredLength }} symbols\n </ng-template>\n </div>\n <div *ngSwitchCase=\"'minlength'\">\n Must contain at least\n {{ control.errors.minlength.requiredLength }} symbols\n </div>\n <div *ngSwitchCase=\"'email'\">Enter a valid Email</div>\n <div *ngSwitchCase=\"'pattern'\">\n Enter a valid {{ propName || 'value' }}\n </div>\n <div *ngSwitchDefault>Required correct field</div>\n </div>\n </div>\n ", styles: ["\n .alert-text {\n position: absolute;\n width: 100%;\n text-align: right;\n color: #980000;\n background-color: transparent;\n font-size: 13px;\n }\n "] }] } ]; /** @nocollapse */ NgxFormValidatorComponent.ctorParameters = function () { return []; }; NgxFormValidatorComponent.propDecorators = { control: [{ type: Input }], propName: [{ type: Input }] }; return NgxFormValidatorComponent; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgxFormValidatorModule = /** @class */ (function () { function NgxFormValidatorModule() { } NgxFormValidatorModule.decorators = [ { type: NgModule, args: [{ declarations: [NgxFormValidatorComponent], imports: [CommonModule ], exports: [NgxFormValidatorComponent] },] } ]; return NgxFormValidatorModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { NgxFormValidatorComponent, NgxFormValidatorModule }; //# sourceMappingURL=ngx-form-validator.js.map