Skip to content

Commit 6ddd55a

Browse files
committed
Serious bug with the input validate method
I was working with some form validation on a public facing site and noticed that the current validationEngine code does not properly validate single input fields in a form. The bug was discovered as an issue of "re-scoping". Within the else block of the methods._validate() function, the valid variable was being rescoped and edited within. However, the variable assignment would not transcend up to the global function variables (see Line 106). As such, I removed the "re-scoping" and added a return !valid because the value of valid after Lines 140-144 is inverted. We need to properly return True for Valid and False for Invalid.
1 parent e48070d commit 6ddd55a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

js/jquery.validationEngine.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,17 @@
133133
element.removeClass('validating');
134134
} else {
135135
// field validation
136-
var form = element.closest('form, .validationEngineContainer'),
137-
options = (form.data('jqv')) ? form.data('jqv') : $.validationEngine.defaults,
138-
valid = methods._validateField(element, options);
136+
var form = element.closest('form, .validationEngineContainer');
137+
options = (form.data('jqv')) ? form.data('jqv') : $.validationEngine.defaults;
138+
valid = methods._validateField(element, options);
139+
140+
if (valid && options.onFieldSuccess)
141+
options.onFieldSuccess();
142+
else if (options.onFieldFailure && options.InvalidFields.length > 0) {
143+
options.onFieldFailure();
144+
}
145+
146+
return !valid;
139147
}
140148
if(options.onValidationComplete) {
141149
// !! ensures that an undefined return is interpreted as return false but allows a onValidationComplete() to possibly return true and have form continue processing

0 commit comments

Comments
 (0)