ws-form-builder
Version:
Ionic 2 Form Builder
67 lines (50 loc) • 1.67 kB
text/typescript
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { FormBuilderProvider } from '../../providers/form-builder/form-builder';
export class WsTextInputComponent {
question;
answerGiven = new EventEmitter();
fieldValue:string = '';
isFieldValid:boolean = false;
showError:boolean = false;
fieldClass:string = '';
constructor(public formBuilder: FormBuilderProvider){
this.fieldValue = '';
}
ngOnInit() {
if(typeof this.question.value !== 'undefined'){
this.fieldValue = this.question.value;
}
if(typeof this.question.inputClass !== 'undefined'){
this.fieldClass = this.question.inputClass;
}
}
setAnswer(event,question){
let isStringValid = this.validateAnswer(question,event.value);
if(!isStringValid){
this.isFieldValid = false;
this.showError = true;
}else{
this.isFieldValid = true;
this.showError = false;
}
if(this.isFieldValid){
question.value = event.value;
question.valid = true;
this.answerGiven.emit(question);
}
}
validateAnswer(question,string){
return this.formBuilder.validateAnswer(question,string);
}
}