UNPKG

ws-form-builder

Version:
60 lines 2.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var form_builder_1 = require("../../providers/form-builder/form-builder"); var WsTextInputComponent = (function () { function WsTextInputComponent(formBuilder) { this.formBuilder = formBuilder; this.answerGiven = new core_1.EventEmitter(); this.fieldValue = ''; this.isFieldValid = false; this.showError = false; this.fieldClass = ''; this.fieldValue = ''; } WsTextInputComponent.prototype.ngOnInit = function () { if (typeof this.question.value !== 'undefined') { this.fieldValue = this.question.value; } if (typeof this.question.inputClass !== 'undefined') { this.fieldClass = this.question.inputClass; } }; WsTextInputComponent.prototype.setAnswer = function (event, question) { var 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); } }; WsTextInputComponent.prototype.validateAnswer = function (question, string) { return this.formBuilder.validateAnswer(question, string); }; WsTextInputComponent.decorators = [ { type: core_1.Component, args: [{ selector: 'ws-text-input', template: "\n <ion-item class=\"ws-input {{fieldClass}}\" [ngClass]=\"(!isFieldValid && showError) ? 'field-error' : ''\">\n <ion-label color=\"primary\" floating *ngIf=\"!question.hideQuestion\">{{question.question}}</ion-label>\n <ion-input placeholder=\"{{question.placeholder}}\" value=\"{{fieldValue}}\" (ionChange)=\"setAnswer($event, question)\" ></ion-input>\n </ion-item>\n ", styles: ["\n\n "] },] }, ]; /** @nocollapse */ WsTextInputComponent.ctorParameters = function () { return [ { type: form_builder_1.FormBuilderProvider, }, ]; }; WsTextInputComponent.propDecorators = { "question": [{ type: core_1.Input, args: ['question',] },], "answerGiven": [{ type: core_1.Output },], }; return WsTextInputComponent; }()); exports.WsTextInputComponent = WsTextInputComponent; //# sourceMappingURL=ws-text-input.js.map