FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[WIP] Add array support with any constraints by nishidayuya · Pull Request #184 · ansman/validate.js · GitHub

This repository was archived by the owner on Dec 12, 2021. It is now read-only.
/ validate.js Public archive
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
67 changes: 67 additions & 0 deletions validate.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,11 @@
expandMultipleErrors: function(errors) {
var ret = [];
errors.forEach(function(error) {
if (v.isFunction(error.error.expand)) {
error.error.expand(ret, error);
return;
}

// Removes errors without a message
if (v.isArray(error.error)) {
error.error.forEach(function(msg) {
Expand Down Expand Up @@ -1144,6 +1149,68 @@
if (!PATTERN.exec(value)) {
return message;
}
},

forEachSingle: function(value, options, attribute, attributes) {
if (!v.isDefined(value)) {
return;
}

var result = {
expand: function(ret, res) {
res.error.data.forEach(function(ary, i) {
if (ary) {
ary.forEach(function(r) {
var attribute = res.attribute + '[' + i + ']';
var o = v.extend({}, r, {
attribute: attribute,
attributes: {}
});
o.attributes[attribute] = r.attributes.single;
ret.push(o);
});
}
});
},
data: []
};
for (var i = 0; i < value.length; i++) {
var r = v({single: value[i]}, {single: options},
{fullMessages: false, format: 'detailed'});
result.data.push(r);
}
return result;
},

forEach: function(value, options, attribute, attributes) {
if (!v.isDefined(value)) {
return;
}

var result = {
expand: function(ret, res) {
res.error.data.forEach(function(ary, i) {
if (ary) {
ary.forEach(function(r) {
var attribute = res.attribute + '[' + i + '].' + r.attribute;
var o = v.extend({}, r, {
attribute: attribute,
attributes: {}
});
o.attributes[attribute] = r.attributes;
ret.push(o);
});
}
});
},
data: []
};
for (var i = 0; i < value.length; i++) {
var r = v(value[i], options,
{fullMessages: false, format: 'detailed'});
result.data.push(r);
}
return result;
}
};

Expand Down

Back | FazBrowse Home | New Git URL