1 var _typeof = typeof Symbol ===
"function" && typeof Symbol.iterator ===
"symbol" ?
function (obj) {
return typeof obj; } :
function (obj) {
return obj && typeof Symbol ===
"function" && obj.constructor === Symbol && obj !== Symbol.prototype ?
"symbol" : typeof obj; };
5 var Validate =
function Validate(table) {
10 Validate.prototype.initializeColumn =
function (column) {
15 if (column.definition.validator) {
17 if (Array.isArray(column.definition.validator)) {
18 column.definition.validator.forEach(
function (item) {
19 validator =
self._extractValidator(item);
22 config.push(validator);
26 validator = this._extractValidator(column.definition.validator);
29 config.push(validator);
33 column.modules.validate = config.length ? config :
false;
37 Validate.prototype._extractValidator =
function (value) {
38 var type, params, pos;
40 switch (typeof value ===
"undefined" ?
"undefined" : _typeof(value)) {
42 pos = value.indexOf(
':');
45 type = value.substring(0, pos);
46 params = value.substring(pos + 1);
51 return this._buildValidator(type, params);
55 return this._buildValidator(value);
59 return this._buildValidator(value.type, value.parameters);
64 Validate.prototype._buildValidator =
function (type, params) {
66 var func = typeof type ==
"function" ? type : this.validators[type];
69 console.warn(
"Validator Setup Error - No matching validator found:", type);
73 type: typeof type ==
"function" ?
"function" : type,
80 Validate.prototype.validate =
function (validators, cell, value) {
85 validators.forEach(
function (item) {
86 if (!item.func.call(
self, cell, value, item.params)) {
89 parameters: item.params
95 return valid.length ? valid :
true;
98 Validate.prototype.validators = {
101 integer:
function integer(cell, value, parameters) {
102 if (value ===
"" || value === null || typeof value ===
"undefined") {
105 value = Number(value);
106 return typeof value ===
'number' && isFinite(value) && Math.floor(value) === value;
110 float:
function float(cell, value, parameters) {
111 if (value ===
"" || value === null || typeof value ===
"undefined") {
114 value = Number(value);
115 return typeof value ===
'number' && isFinite(value) && value % 1 !== 0;
119 numeric:
function numeric(cell, value, parameters) {
120 if (value ===
"" || value === null || typeof value ===
"undefined") {
123 return !isNaN(value);
127 string:
function string(cell, value, parameters) {
128 if (value ===
"" || value === null || typeof value ===
"undefined") {
135 max:
function max(cell, value, parameters) {
136 if (value ===
"" || value === null || typeof value ===
"undefined") {
139 return parseFloat(value) <= parameters;
143 min:
function min(cell, value, parameters) {
144 if (value ===
"" || value === null || typeof value ===
"undefined") {
147 return parseFloat(value) >= parameters;
151 minLength:
function minLength(cell, value, parameters) {
152 if (value ===
"" || value === null || typeof value ===
"undefined") {
155 return String(value).length >= parameters;
159 maxLength:
function maxLength(cell, value, parameters) {
160 if (value ===
"" || value === null || typeof value ===
"undefined") {
163 return String(value).length <= parameters;
167 in:
function _in(cell, value, parameters) {
168 if (value ===
"" || value === null || typeof value ===
"undefined") {
171 if (typeof parameters ==
"string") {
172 parameters = parameters.split(
"|");
175 return value ===
"" || parameters.indexOf(value) > -1;
179 regex:
function regex(cell, value, parameters) {
180 if (value ===
"" || value === null || typeof value ===
"undefined") {
183 var reg =
new RegExp(parameters);
185 return reg.test(value);
189 unique:
function unique(cell, value, parameters) {
190 if (value ===
"" || value === null || typeof value ===
"undefined") {
195 var cellData = cell.getData();
196 var column = cell.getColumn()._getSelf();
198 this.table.rowManager.rows.forEach(
function (row) {
199 var data = row.getData();
201 if (data !== cellData) {
202 if (value == column.getFieldValue(data)) {
212 required:
function required(cell, value, parameters) {
213 return value !==
"" && value !== null && typeof value !==
"undefined";
217 Tabulator.prototype.registerModule(
"validate", Validate);