UNPKG

ngx-form-validator

Version:

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

104 lines (96 loc) 5.33 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs/index'), require('rxjs/internal/operators'), require('@angular/core'), require('@angular/common')) : typeof define === 'function' && define.amd ? define('ngx-form-validator', ['exports', 'rxjs/index', 'rxjs/internal/operators', '@angular/core', '@angular/common'], factory) : (factory((global['ngx-form-validator'] = {}),global.rxjs.index,global.rxjs['internal/operators'],global.ng.core,global.ng.common)); }(this, (function (exports,index,operators,core,common) { 'use strict'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgxFormValidatorComponent = /** @class */ (function () { function NgxFormValidatorComponent() { this.destroy$ = new index.Subject(); } /** * @return {?} */ NgxFormValidatorComponent.prototype.ngOnInit = /** * @return {?} */ function () { this.initControl(); }; /** * @return {?} */ NgxFormValidatorComponent.prototype.initControl = /** * @return {?} */ function () { var _this = this; this.control.statusChanges .pipe(operators.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: core.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: core.Input }], propName: [{ type: core.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: core.NgModule, args: [{ declarations: [NgxFormValidatorComponent], imports: [common.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 */ exports.NgxFormValidatorComponent = NgxFormValidatorComponent; exports.NgxFormValidatorModule = NgxFormValidatorModule; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=ngx-form-validator.umd.js.map