ws-form-builder
Version:
Ionic 2 Form Builder
108 lines (82 loc) • 3.41 kB
text/typescript
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { FormBuilderProvider } from '../../providers/form-builder/form-builder';
export class WsSingleRangeSliderComponent {
question;
answerGiven = new EventEmitter();
step:number = 1;
minValue:number = 0;
maxValue:number = 100;
snaps:boolean = false;
fieldValue:number = 20;
isFieldValid:boolean = false;
showError:boolean = false;
iconLeft:string = '';
iconRight:string = '';
showNumber:boolean = true;
fieldClass:string = '';
constructor(public formBuilder: FormBuilderProvider){
}
ngOnInit() {
if(typeof this.question.step !== 'undefined'){
this.step = this.question.step;
}
if(typeof this.question.maxNumber !== 'undefined'){
this.maxValue = this.question.maxNumber;
}
if(typeof this.question.minNumber !== 'undefined'){
this.minValue = this.question.minNumber;
}
if(typeof this.question.snaps !== 'undefined'){
this.snaps = this.question.snaps;
}
if(typeof this.question.iconLeft !== 'undefined' && this.question.iconLeft !== ''){
this.iconLeft = this.question.iconLeft;
}
if(typeof this.question.iconRight !== 'undefined' && this.question.iconRight !== ''){
this.iconRight = this.question.iconRight;
}
if(typeof this.question.showNumber !== 'undefined'){
this.showNumber = this.question.showNumber;
}
if(typeof this.question.defaultNumber !== 'undefined' && this.question.defaultNumber !== ''){
this.fieldValue = this.question.defaultNumber;
}
if(typeof this.question.value !== 'undefined' && this.question.value !== ''){
this.fieldValue = this.question.value;
}
if(typeof this.question.inputClass !== 'undefined'){
this.fieldClass = this.question.inputClass;
}
}
setAnswer(event){
if(this.fieldValue){
this.question.value = this.fieldValue;
this.question.valid = true;
this.answerGiven.emit(this.question);
}
}
validateAnswer(question,string){
return this.formBuilder.validateAnswer(question,string);
}
}