Skip to content

Commit

Permalink
Release: v1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tabalinas committed Feb 21, 2016
1 parent 4f8c590 commit f5e34bd
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsgrid",
"version": "1.4.0",
"version": "1.4.1",
"main": [
"dist/jsgrid.js",
"dist/jsgrid.css",
Expand Down
2 changes: 1 addition & 1 deletion dist/jsgrid-theme.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jsgrid-theme.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jsgrid.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jsGrid v1.4.0 (http://js-grid.com)
* jsGrid v1.4.1 (http://js-grid.com)
* (c) 2016 Artem Tabalin
* Licensed under MIT (https://github.com/tabalinas/jsgrid/blob/master/LICENSE)
*/
Expand Down
142 changes: 139 additions & 3 deletions dist/jsgrid.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jsGrid v1.4.0 (http://js-grid.com)
* jsGrid v1.4.1 (http://js-grid.com)
* (c) 2016 Artem Tabalin
* Licensed under MIT (https://github.com/tabalinas/jsgrid/blob/master/LICENSE)
*/
Expand Down Expand Up @@ -665,7 +665,7 @@
var current = item;
var prop = props[0];

while(current && props.length > 1) {
while(current && props.length) {
item = current;
prop = props.shift();
current = item[prop];
Expand Down Expand Up @@ -1127,7 +1127,7 @@
return;

var errors = this._validation.validate($.extend({
value: item[field.name],
value: this._getItemFieldValue(item, field),
rules: field.validate
}, args));

Expand Down Expand Up @@ -1662,6 +1662,142 @@

}(jsGrid, jQuery));

(function(jsGrid, $, undefined) {

function Validation(config) {
this._init(config);
}

Validation.prototype = {

_init: function(config) {
$.extend(true, this, config);
},

validate: function(args) {
var errors = [];

$.each(this._normalizeRules(args.rules), function(_, rule) {
if(rule.validator(args.value, args.item, rule.param))
return;

var errorMessage = $.isFunction(rule.message) ? rule.message(args.value, args.item) : rule.message;
errors.push(errorMessage);
});

return errors;
},

_normalizeRules: function(rules) {
if(!$.isArray(rules))
rules = [rules];

return $.map(rules, $.proxy(function(rule) {
return this._normalizeRule(rule);
}, this));
},

_normalizeRule: function(rule) {
if(typeof rule === "string")
rule = { validator: rule };

if($.isFunction(rule))
rule = { validator: rule };

if($.isPlainObject(rule))
rule = $.extend({}, rule);
else
throw Error("wrong validation config specified");

if($.isFunction(rule.validator))
return rule;

return this._applyNamedValidator(rule, rule.validator);
},

_applyNamedValidator: function(rule, validatorName) {
delete rule.validator;

var validator = validators[validatorName];
if(!validator)
throw Error("unknown validator \"" + validatorName + "\"");

if($.isFunction(validator)) {
validator = { validator: validator };
}

return $.extend({}, validator, rule);
}
};

jsGrid.Validation = Validation;


var validators = {
required: {
message: "Field is required",
validator: function(value) {
return value !== undefined && value !== null && value !== "";
}
},

rangeLength: {
message: "Field value length is out of the defined range",
validator: function(value, _, param) {
return value.length >= param[0] && value.length <= param[1];
}
},

minLength: {
message: "Field value is too long",
validator: function(value, _, param) {
return value.length >= param;
}
},

maxLength: {
message: "Field value is too short",
validator: function(value, _, param) {
return value.length <= param;
}
},

pattern: {
message: "Field value is not matching the defined pattern",
validator: function(value, _, param) {
if(typeof param === "string") {
param = new RegExp("^(?:" + param + ")$");
}
return param.test(value);
}
},

range: {
message: "Field value is out of the defined range",
validator: function(value, _, param) {
return value >= param[0] && value <= param[1];
}
},

min: {
message: "Field value is too large",
validator: function(value, _, param) {
return value >= param;
}
},

max: {
message: "Field value is too small",
validator: function(value, _, param) {
return value <= param;
}
}
};

jsGrid.validators = validators;

}(jsGrid, jQuery));

(function(jsGrid, $, undefined) {

function Field(config) {
Expand Down
2 changes: 1 addition & 1 deletion dist/jsgrid.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/jsgrid.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsgrid",
"version": "1.4.0",
"version": "1.4.1",
"description": "Lightweight data grid jQuery plugin. It supports basic grid operations like inserting, filtering, editing, deleting, paging and sorting. Although jsGrid is tunable and allows to customize appearance and components.",
"keywords": [
"grid",
Expand Down

0 comments on commit f5e34bd

Please sign in to comment.