import {Component, OnInit, Input} from '@angular/core'; import { FormControl, Validators } from '@angular/forms'; import { InputBoxOptions } from './InputBoxOptions'; import { Defaults } from '../../constant/defaults.constant'; import { Helper } from '../../helper'; @Component({ selector: 'rss-input-box', templateUrl: './input-box.component.html', styleUrls: ['./input-box.component.scss'] }) export class InputBoxComponent implements OnInit { @Input() config; @Input() control: FormControl; @Input() readonly: Boolean; @Input() label: any; @Input() placeholder = Defaults.PLACEHOLDER; @Input() required: boolean = Defaults.REQUIRED; @Input() requiredError: string = Defaults.REQUIRED_ERROR_MESSAGE; @Input() type: string = Defaults.INPUT_TYPE; emptyResponseMsg = Defaults.EMPTY_RESPONSE_MSG; constructor() { } ngOnInit() { if (this.config) { const config = new InputBoxOptions(this.config); Helper.merge(this, config); } if (!this.control) { console.error(Defaults.MISSING_FORM_CONTROL_ERROR_MESSAGE); } else { if (this.required) { this.control.setValidators(Validators.required); } } } displayRequiredError(fc: FormControl) { return Helper.displayRequiredError(fc); } }