ws-form-builder
Version:
Ionic 2 Form Builder
91 lines • 3.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
//import { HttpClient } from '@angular/common/http';
var core_1 = require("@angular/core");
var ionic_angular_1 = require("ionic-angular");
var FormBuilderProvider = (function () {
function FormBuilderProvider(platform) {
this.platform = platform;
this.avalibleValidators = [];
}
FormBuilderProvider.prototype.detectDevice = function () {
if (this.platform.is('cordova')) {
return true;
}
else {
return false;
}
};
FormBuilderProvider.prototype.isEmail = function (email) {
//returns true if email
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
};
FormBuilderProvider.prototype.checkAgainstCustomRegex = function (regex, string) {
return regex.test(string);
};
FormBuilderProvider.prototype.isNumbersOnly = function (string) {
//returns true if string only containts numbers
return /^\d+$/.test(string);
};
FormBuilderProvider.prototype.isEmpty = function (string) {
//if empty return true
if (string.length == 0) {
return true;
}
return false;
};
FormBuilderProvider.prototype.validateAnswer = function (question, string) {
var status = true;
//check if field is required
if (typeof question.required !== 'undefined') {
if (question.required) {
if (this.isEmpty(string)) {
status = false;
}
}
}
//check the string meets the minimum length
if (typeof question.minLength !== 'undefined') {
if (string.length < question.minLength) {
status = false;
}
}
//check the string meets the maximum length
if (typeof question.maxLength !== 'undefined') {
if (string.length > question.maxLength) {
status = false;
}
}
if (typeof question.validators !== 'undefined') {
if (typeof question.validators.validators !== 'undefined') {
if (question.validators.validators.includes('email')) {
if (!this.isEmail(string)) {
status = false;
}
}
if (question.validators.validators.includes('numbersOnly')) {
if (!this.isNumbersOnly(string)) {
status = false;
}
}
}
if (typeof question.validators.customRegex !== 'undefined') {
if (!this.checkAgainstCustomRegex(question.validators.customRegex, string)) {
return status;
}
}
}
return status;
};
FormBuilderProvider.decorators = [
{ type: core_1.Injectable },
];
/** @nocollapse */
FormBuilderProvider.ctorParameters = function () { return [
{ type: ionic_angular_1.Platform, },
]; };
return FormBuilderProvider;
}());
exports.FormBuilderProvider = FormBuilderProvider;
//# sourceMappingURL=form-builder.js.map