import { Component, OnInit, Input, Output, ElementRef, EventEmitter } from '@angular/core'; import { CfCoreComponent } from '../core/core.component'; import { FormGroup,ReactiveFormsModule } from '@angular/forms'; import { InputModel } from '../../models/input/input.model'; import { SelectableModel } from '../../models/selectable/selectable.model'; import { GroupModel } from '../../models/group/group.model'; @Component({ selector: 'cf-form-question', template: " ", styles: [".errorMessage { font-family: 'Avenir'; color: red; font-size: 10px; } [hidden] { display: none !important; } "] }) export class CfFormQuestionComponent extends CfCoreComponent implements OnInit { @Input() question: any; @Input() form: FormGroup; get isValid() { return this.form.controls[this.question.key].valid || !this.form.controls[this.question.key].dirty; } private properties: any; constructor(public elementRef: ElementRef) { super(elementRef); } ngOnInit() { var addAsterix =""; if(this.question["required"]!=null && this.question["required"]==true) { addAsterix="*";} this.populateProperties(addAsterix); } populateProperties(addAsterix){ switch(this.question["componentType"]) { case "input": { this.properties = new InputModel({ type: this.question["type"], placeholder: this.question["label"]+addAsterix, value: this.question["value"], maxLength: this.question["maxLength"] }); break; } case "checkbox": case "switch": case "radio": { this.properties = []; this.question["label"]= this.question["label"]+addAsterix; for(let item of this.question.items) { var chec = new SelectableModel({ item: item["label"], value: item["value"] }); this.properties.push(chec); } break; } } } }