Skip to content

Commit 30338a0

Browse files
committed
Version 1.5.3
- Fixed possible JSON iteration issue - Fixed Error display if there was a <ul> inside the form and display set to 'block' - onSubmit formData now returns the complete data
1 parent 7a5e2c3 commit 30338a0

File tree

5 files changed

+209
-192
lines changed

5 files changed

+209
-192
lines changed

dist/jquery.validation.js

Lines changed: 134 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Licensed under the MIT license
55
*
66
* @author Tom Bertrand
7-
* @version 2.0.0 (2015-04-22)
7+
* @version 1.5.3 (2015-06-14)
88
* @link http://www.runningcoder.org/jqueryvalidation/
99
*/
1010
;
@@ -22,117 +22,117 @@
2222
};
2323
}
2424
var _rules = {
25-
NOTEMPTY: /\S/,
26-
INTEGER: /^\d+$/,
27-
NUMERIC: /^\d+(?:[,\s]\d{3})*(?:\.\d+)?$/,
28-
MIXED: /^[\w\s-]+$/,
29-
NAME: /^['a-zãàáäâèéëêìíïîõòóöôùúüûñç\s-]+$/i,
30-
NOSPACE: /^(?!\s)\S*$/,
31-
TRIM: /^[^\s].*[^\s]$/,
32-
DATE: /^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}(:\d{2})?)?$/,
33-
EMAIL: /^([^@]+?)@(([a-z0-9]-*)*[a-z0-9]+\.)+([a-z0-9]+)$/i,
34-
URL: /^(https?:\/\/)?((([a-z0-9]-*)*[a-z0-9]+\.?)*([a-z0-9]+))(\/[\w?=\.-]*)*$/,
35-
PHONE: /^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/,
36-
OPTIONAL: /\S/,
37-
COMPARISON: /^\s*([LV])\s*([<>]=?|==|!=)\s*([^<>=!]+?)\s*$/
38-
},
25+
NOTEMPTY: /\S/,
26+
INTEGER: /^\d+$/,
27+
NUMERIC: /^\d+(?:[,\s]\d{3})*(?:\.\d+)?$/,
28+
MIXED: /^[\w\s-]+$/,
29+
NAME: /^['a-zãàáäâèéëêìíïîõòóöôùúüûñç\s-]+$/i,
30+
NOSPACE: /^(?!\s)\S*$/,
31+
TRIM: /^[^\s].*[^\s]$/,
32+
DATE: /^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}(:\d{2})?)?$/,
33+
EMAIL: /^([^@]+?)@(([a-z0-9]-*)*[a-z0-9]+\.)+([a-z0-9]+)$/i,
34+
URL: /^(https?:\/\/)?((([a-z0-9]-*)*[a-z0-9]+\.?)*([a-z0-9]+))(\/[\w?=\.-]*)*$/,
35+
PHONE: /^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/,
36+
OPTIONAL: /\S/,
37+
COMPARISON: /^\s*([LV])\s*([<>]=?|==|!=)\s*([^<>=!]+?)\s*$/
38+
};
3939

40-
_messages = {
41-
'default': '$ contain error(s).',
42-
'NOTEMPTY': '$ must not be empty.',
43-
'INTEGER': '$ must be an integer.',
44-
'NUMERIC': '$ must be numeric.',
45-
'MIXED': '$ must be letters or numbers (no special characters).',
46-
'NAME': '$ must not contain special characters.',
47-
'NOSPACE': '$ must not contain spaces.',
48-
'TRIM': '$ must not start or end with space character.',
49-
'DATE': '$ is not a valid with format YYYY-MM-DD.',
50-
'EMAIL': '$ is not valid.',
51-
'URL': '$ is not valid.',
52-
'PHONE': '$ is not a valid phone number.',
53-
'<': '$ must be less than % characters.',
54-
'<=': '$ must be less or equal to % characters.',
55-
'>': '$ must be greater than % characters.',
56-
'>=': '$ must be greater or equal to % characters.',
57-
'==': '$ must be equal to %',
58-
'!=': '$ must be different than %'
59-
},
40+
var _messages = {
41+
'default': '$ contain error(s).',
42+
'NOTEMPTY': '$ must not be empty.',
43+
'INTEGER': '$ must be an integer.',
44+
'NUMERIC': '$ must be numeric.',
45+
'MIXED': '$ must be letters or numbers (no special characters).',
46+
'NAME': '$ must not contain special characters.',
47+
'NOSPACE': '$ must not contain spaces.',
48+
'TRIM': '$ must not start or end with space character.',
49+
'DATE': '$ is not a valid with format YYYY-MM-DD.',
50+
'EMAIL': '$ is not valid.',
51+
'URL': '$ is not valid.',
52+
'PHONE': '$ is not a valid phone number.',
53+
'<': '$ must be less than % characters.',
54+
'<=': '$ must be less or equal to % characters.',
55+
'>': '$ must be greater than % characters.',
56+
'>=': '$ must be greater or equal to % characters.',
57+
'==': '$ must be equal to %',
58+
'!=': '$ must be different than %'
59+
};
6060

61-
_data = {
62-
validation: 'data-validation',
63-
validationMessage: 'data-validation-message',
64-
regex: 'data-validation-regex',
65-
regexReverse: 'data-validation-regex-reverse',
66-
regexMessage: 'data-validation-regex-message',
67-
group: 'data-validation-group',
68-
label: 'data-validation-label',
69-
errorList: 'data-error-list'
70-
},
61+
var _data = {
62+
validation: 'data-validation',
63+
validationMessage: 'data-validation-message',
64+
regex: 'data-validation-regex',
65+
regexReverse: 'data-validation-regex-reverse',
66+
regexMessage: 'data-validation-regex-message',
67+
group: 'data-validation-group',
68+
label: 'data-validation-label',
69+
errorList: 'data-error-list'
70+
}
7171

72-
_options = {
73-
submit: {
74-
settings: {
75-
form: null,
76-
display: "inline",
77-
insertion: "append",
78-
allErrors: false,
79-
trigger: "click",
80-
button: "[type='submit']",
81-
errorClass: "error",
82-
errorListClass: "error-list",
83-
errorListContainer: null,
84-
inputContainer: null,
85-
clear: "focusin",
86-
scrollToError: false
87-
},
88-
callback: {
89-
onInit: null,
90-
onValidate: null,
91-
onError: null,
92-
onBeforeSubmit: null,
93-
onSubmit: null,
94-
onAfterSubmit: null
95-
}
72+
var _options = {
73+
submit: {
74+
settings: {
75+
form: null,
76+
display: "inline",
77+
insertion: "append",
78+
allErrors: false,
79+
trigger: "click",
80+
button: "[type='submit']",
81+
errorClass: "error",
82+
errorListClass: "error-list",
83+
errorListContainer: null,
84+
inputContainer: null,
85+
clear: "focusin",
86+
scrollToError: false
9687
},
97-
dynamic: {
98-
settings: {
99-
trigger: null,
100-
delay: 300
101-
},
102-
callback: {
103-
onSuccess: null,
104-
onError: null,
105-
onComplete: null
106-
}
88+
callback: {
89+
onInit: null,
90+
onValidate: null,
91+
onError: null,
92+
onBeforeSubmit: null,
93+
onSubmit: null,
94+
onAfterSubmit: null
95+
}
96+
},
97+
dynamic: {
98+
settings: {
99+
trigger: null,
100+
delay: 300
107101
},
108-
rules: {},
109-
messages: {},
110-
labels: {},
111-
debug: false
102+
callback: {
103+
onSuccess: null,
104+
onError: null,
105+
onComplete: null
106+
}
112107
},
108+
rules: {},
109+
messages: {},
110+
labels: {},
111+
debug: false
112+
};
113113

114-
_supported = {
115-
submit: {
116-
settings: {
117-
display: ["inline", "block"],
118-
insertion: ["append", "prepend"], //"before", "insertBefore", "after", "insertAfter"
119-
allErrors: [true, false],
120-
clear: ["focusin", "keypress", false],
121-
trigger: [
122-
"click", "dblclick", "focusout",
123-
"hover", "mousedown", "mouseenter",
124-
"mouseleave", "mousemove", "mouseout",
125-
"mouseover", "mouseup", "toggle"
126-
]
127-
}
128-
},
129-
dynamic: {
130-
settings: {
131-
trigger: ["focusout", "keydown", "keypress", "keyup"]
132-
}
133-
},
134-
debug: [true, false]
135-
};
114+
var _supported = {
115+
submit: {
116+
settings: {
117+
display: ["inline", "block"],
118+
insertion: ["append", "prepend"], //"before", "insertBefore", "after", "insertAfter"
119+
allErrors: [true, false],
120+
clear: ["focusin", "keypress", false],
121+
trigger: [
122+
"click", "dblclick", "focusout",
123+
"hover", "mousedown", "mouseenter",
124+
"mouseleave", "mousemove", "mouseout",
125+
"mouseover", "mouseup", "toggle"
126+
]
127+
}
128+
},
129+
dynamic: {
130+
settings: {
131+
trigger: ["focusout", "keydown", "keypress", "keyup"]
132+
}
133+
},
134+
debug: [true, false]
135+
};
136136

137137
var Validation = function(node, options) {
138138

@@ -252,7 +252,6 @@
252252
options.debug && window.Debug.log({
253253
'node': node,
254254
'function': 'delegateDynamicValidation()',
255-
'arguments': JSON.stringify(options),
256255
'message': 'OK - Dynamic Validation activated on ' + node.length + ' form(s)'
257256
});
258257

@@ -315,7 +314,6 @@
315314
options.debug && window.Debug.log({
316315
'node': node,
317316
'function': 'delegateValidation()',
318-
'arguments': JSON.stringify(options),
319317
'message': 'OK - Validation activated on ' + node.length + ' form(s)'
320318
});
321319

@@ -368,11 +366,24 @@
368366

369367
formData = {};
370368

369+
371370
$.each(
372-
node.find('[' + _data.validation + ']:not([disabled]),[' + _data.regex + ']:not([disabled])'),
371+
node.find('input:not([type="submit"]), select, textarea'),
373372
function(index, input) {
374-
if (!validateInput(input)) {
375-
isValid = false;
373+
374+
input = $(input);
375+
376+
var value = _getInputValue(input[0]),
377+
inputName = input.attr('name');
378+
379+
if (inputName) {
380+
formData[inputName] = value;
381+
}
382+
383+
if (!input.attr('disabled') && (!!input.attr(_data.validation) || !!input.attr(_data.regex))) {
384+
if (!validateInput(input[0], value)) {
385+
isValid = false;
386+
}
376387
}
377388
}
378389
);
@@ -422,9 +433,10 @@
422433

423434
}
424435

425-
function validateInput(input) {
436+
function validateInput(input, value) {
426437

427-
var inputName = $(input).attr('name');
438+
var inputName = $(input).attr('name'),
439+
value = value || _getInputValue(input);
428440

429441
if (!inputName) {
430442
options.debug && window.Debug.log({
@@ -437,9 +449,7 @@
437449
return false;
438450
}
439451

440-
var value = _getInputValue(input),
441-
442-
matches = inputName.replace(/]$/, '').split(/]\[|[[\]]/g),
452+
var matches = inputName.replace(/]$/, '').split(/]\[|[[\]]/g),
443453
inputShortName = window.Validation.labels[inputName] ||
444454
options.labels[inputName] ||
445455
$(input).attr(_data.label) ||
@@ -453,8 +463,6 @@
453463

454464
validateOnce = false;
455465

456-
formData[inputName] = value;
457-
458466
if (validationArray) {
459467
validationArray = _api._splitValidation(validationArray);
460468
}
@@ -715,7 +723,7 @@
715723
}
716724

717725
for (var i = 0; i < errors[inputName].length; i++) {
718-
errorContainer.find('ul').append('<li>' + errors[inputName][i] + '</li>');
726+
errorContainer.find('[' + _data.errorList + '] ul').append('<li>' + errors[inputName][i] + '</li>');
719727
}
720728

721729
if (options.submit.settings.clear || options.dynamic.settings.trigger) {
@@ -1056,7 +1064,7 @@
10561064
if (!node[0] || node[0].nodeName.toLowerCase() !== "form") {
10571065
window.Debug.log({
10581066
'function': '$.validate()',
1059-
'arguments': JSON.stringify(options.submit.settings.form),
1067+
'arguments': options.submit.settings.form,
10601068
'message': 'Unable to find jQuery form element - Validation dropped'
10611069
});
10621070

@@ -1187,7 +1195,7 @@
11871195
window.Debug.log({
11881196
'node': node,
11891197
'function': '$.addError()',
1190-
'arguments': 'window.Validation.form[' + JSON.stringify(node.selector) + ']',
1198+
'arguments': 'window.Validation.form[' + node.selector + ']',
11911199
'message': 'ERROR - Invalid node selector'
11921200
});
11931201

@@ -1200,7 +1208,7 @@
12001208
window.Debug.log({
12011209
'node': node,
12021210
'function': '$.addError()',
1203-
'arguments': 'window.Validation.form[' + JSON.stringify(node.selector) + ']',
1211+
'arguments': 'window.Validation.form[' + node.selector + ']',
12041212
'message': 'ERROR - Invalid argument, must be type object'
12051213
});
12061214

@@ -1226,7 +1234,7 @@
12261234
window.Debug.log({
12271235
'node': node,
12281236
'function': '$.addError()',
1229-
'arguments': JSON.stringify(inputName),
1237+
'arguments': inputName,
12301238
'message': 'ERROR - Unable to find ' + '$(' + node.selector + ').find("[name="' + inputName + '"]")'
12311239
});
12321240

@@ -1248,7 +1256,7 @@
12481256
window.Debug.log({
12491257
'node': node,
12501258
'function': '$.addError()',
1251-
'arguments': JSON.stringify(error[inputName][i]),
1259+
'arguments': error[inputName][i],
12521260
'message': 'ERROR - Invalid error object property - Accepted format: {"inputName": "errorString"} or {"inputName": ["errorString", "errorString"]}'
12531261
});
12541262

@@ -1273,7 +1281,7 @@
12731281
window.Debug.log({
12741282
'node': node,
12751283
'function': '$.removeError()',
1276-
'arguments': 'window.Validation.form[' + JSON.stringify(node.selector) + ']',
1284+
'arguments': 'window.Validation.form[' + node.selector + ']',
12771285
'message': 'ERROR - Invalid node selector'
12781286
});
12791287

@@ -1291,7 +1299,7 @@
12911299
window.Debug.log({
12921300
'node': node,
12931301
'function': '$.removeError()',
1294-
'arguments': JSON.stringify(inputName),
1302+
'arguments': inputName,
12951303
'message': 'ERROR - Invalid inputName, must be type String or Array'
12961304
});
12971305

@@ -1312,7 +1320,7 @@
13121320
window.Debug.log({
13131321
'node': node,
13141322
'function': '$.removeError()',
1315-
'arguments': JSON.stringify(inputName[i]),
1323+
'arguments': inputName[i],
13161324
'message': 'ERROR - Unable to find ' + '$(' + node.selector + ').find("[name="' + inputName[i] + '"]")'
13171325
});
13181326

0 commit comments

Comments
 (0)