import { Input } from '@angular/core'; import { RdComponent } from '../../base/rdComponent'; import { RdLib } from '../../base/rdLib'; export class InputBase extends RdComponent { @Input("rd-custom-validation-rules") customValidationRules: Array = []; container; dxElement; validator; translateEn = RdLib.localization.translateEn; isValid() { this.updateValidator(); if (this.validator) return this.validator.validate().isValid; else return true; } updateValidator = function () { var self: InputBase = this; let rules = []; this.container.dxValidator({ validationRules: [], onInitialized: (e) => { self.validator = e.component; self.validator.validate(); } }); if (this.required) { rules.push({ type: "required", message: this.warningText ? this.warningText : this.translateEn("Required") }); } if (this.mode == 'email') { rules.push({ type: "email", message: this.translateEn("Email is invalid") }); } if (this.minLength) { rules.push({ type: 'stringLength', min: this.minLength, message: this.translateEn("Minimum") + ' ' + this.minLength + ' ' + this.translateEn("characters must be entered") }) } if (this.validator) self.validator.validate(); this.container.dxValidator({ validationRules: [...rules, ...this.customValidationRules] }); }; onChange = function (value) { this.modelChange.emit(value); this.changeEvent.emit(value); }; checkDefault = function () { if (this.model == null || this.model == undefined) this.model = this.default; this.onChange(this.model); } }