ws-form-builder
Version:
Ionic 2 Form Builder
139 lines (99 loc) • 3.58 kB
text/typescript
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { FormBuilderProvider } from '../../providers/form-builder/form-builder';
export class WsPasswordInputComponent {
question;
answerGiven = new EventEmitter();
fieldValue:string = '';
fieldConfirmValue:string = '';
isFieldValid:boolean = false;
showError:boolean = false;
isConfirmFieldValid:boolean = false;
showConfirmError:boolean = false;
showConfirmField:boolean = false;
confirmLabel:string = '';
errorMessage:string = '';
fieldClass:string = '';
constructor(public formBuilder: FormBuilderProvider){
this.fieldValue = '';
this.fieldConfirmValue = '';
}
ngOnInit() {
if(typeof this.question.addConfirmField !== 'undefined'){
this.showConfirmField = this.question.addConfirmField;
}
if(typeof this.question.confirmLabel !== 'undefined'){
this.confirmLabel = this.question.confirmLabel;
}
if(typeof this.question.inputClass !== 'undefined'){
this.fieldClass = this.question.inputClass;
}
}
setConfirmAnswer(event,question){
this.fieldConfirmValue = event.value;
this.errorMessage = '';
let isStringValid = this.validateAnswer(question,event.value);
question.valid = false;
//compare password fields
if(!isStringValid){
this.isConfirmFieldValid = false;
this.showConfirmError = true;
}else{
this.isConfirmFieldValid = true;
this.showConfirmError = false;
}
if(this.fieldValue !== this.fieldConfirmValue && this.showConfirmField !== false){
this.errorMessage = 'Passwords do no match!';
this.isConfirmFieldValid = false;
this.showConfirmError = true;
}else{
this.isFieldValid = true;
this.showError = false;
}
if(this.isConfirmFieldValid){
question.value = event.value;
question.valid = true;
this.answerGiven.emit(question);
}
}
setAnswer(event,question){
this.fieldValue = event.value;
this.errorMessage = '';
question.valid = false;
let isStringValid = this.validateAnswer(question,event.value);
//compare password fields
if(!isStringValid){
this.isFieldValid = false;
this.showError = true;
}else{
this.isFieldValid = true;
this.showError = false;
}
if(this.isFieldValid){
question.value = event.value;
if(this.showConfirmField === false){
question.valid = true;
}
this.answerGiven.emit(question);
}
}
validateAnswer(question,string){
return this.formBuilder.validateAnswer(question,string);
}
}