UNPKG

fe-validate

Version:

angular 2+ form validate

114 lines (113 loc) 4.46 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ import { Component, ContentChildren, ElementRef, HostBinding, Input, QueryList } from "@angular/core"; import { FormControlName } from "@angular/forms"; import { ErrorMessage } from "./message.models"; import { ErrorMessageService } from "./message.service"; var FormValidateComponent = /** @class */ (function () { function FormValidateComponent(elRef, errorMessageService) { this.elRef = elRef; this.errorMessageService = errorMessageService; } Object.defineProperty(FormValidateComponent.prototype, "hasErrors", { get: /** * @return {?} */ function () { return this.FormControlNames.some(function (c) { return !c.valid && c.dirty && c.touched; }) && !this.validationDisabled; }, enumerable: true, configurable: true }); Object.defineProperty(FormValidateComponent.prototype, "hasSuccess", { get: /** * @return {?} */ function () { return !this.FormControlNames.some(function (c) { return !c.valid; }) && this.FormControlNames.some(function (c) { return c.dirty && c.touched; }) && !this.validationDisabled; }, enumerable: true, configurable: true }); Object.defineProperty(FormValidateComponent.prototype, "label", { get: /** * @return {?} */ function () { var /** @type {?} */ label = this.elRef.nativeElement.querySelector('.form-control').getAttribute('placeholder'); // this.elRef.nativeElement.querySelector('label'); // return label && label.textContent ? label.textContent.trim() : ''; return label ? label.trim() : ''; }, enumerable: true, configurable: true }); Object.defineProperty(FormValidateComponent.prototype, "isDirtyAndTouched", { get: /** * @return {?} */ function () { return this.FormControlNames.some(function (c) { return c.dirty && c.touched; }); }, enumerable: true, configurable: true }); Object.defineProperty(FormValidateComponent.prototype, "errorMessages", { get: /** * @return {?} */ function () { return this.errorMessageService.mergeArray(this.customErrorMessages, this.errorMessageService.errorMessages); }, enumerable: true, configurable: true }); Object.defineProperty(FormValidateComponent.prototype, "messages", { get: /** * @return {?} */ function () { var _this = this; var /** @type {?} */ messages = []; if (!this.isDirtyAndTouched || this.validationDisabled) return messages; this.FormControlNames.filter(function (c) { return !c.valid; }).forEach(function (control) { if (control.errors) { Object.keys(control.errors).forEach(function (key) { var /** @type {?} */ error = _this.errorMessages.find(function (error) { return error.error === key; }); if (!error) return; messages.push(error.format(_this.label, control.errors[key])); }); } }); return messages; }, enumerable: true, configurable: true }); return FormValidateComponent; }()); export { FormValidateComponent }; function FormValidateComponent_tsickle_Closure_declarations() { /** @type {!Array<{type: !Function, args: (undefined|!Array<?>)}>} */ FormValidateComponent.decorators; /** * @nocollapse * @type {function(): !Array<(null|{type: ?, decorators: (undefined|!Array<{type: !Function, args: (undefined|!Array<?>)}>)})>} */ FormValidateComponent.ctorParameters; /** @type {!Object<string,!Array<{type: !Function, args: (undefined|!Array<?>)}>>} */ FormValidateComponent.propDecorators; /** @type {?} */ FormValidateComponent.prototype.FormControlNames; /** @type {?} */ FormValidateComponent.prototype.customErrorMessages; /** @type {?} */ FormValidateComponent.prototype.validationDisabled; /** @type {?} */ FormValidateComponent.prototype.elRef; /** @type {?} */ FormValidateComponent.prototype.errorMessageService; }