Skip to content

Commit 3d19ab9

Browse files
committed
Added ignore field feature
very useful on dynamic forms and for example when you have hidden fields inside TABS (so you are forced to enable the "validateNonVisibleFields") BUT you still have others hidden fields you don't want to validate
1 parent ab894c7 commit 3d19ab9

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

js/jquery.validationEngine.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
var form = element.closest('form, .validationEngineContainer'),
134134
options = (form.data('jqv')) ? form.data('jqv') : $.validationEngine.defaults,
135135
valid = methods._validateField(element, options);
136-
}
137136
}
138137
if(options.onValidationComplete) {
139138
// !! ensures that an undefined return is interpreted as return false but allows a onValidationComplete() to possibly return true and have form continue processing
@@ -520,6 +519,9 @@
520519
++$.validationEngine.fieldIdCounter;
521520
}
522521

522+
if(field.hasClass(options.ignoreFieldsWithClass))
523+
return false;
524+
523525
if (!options.validateNonVisibleFields && (field.is(":hidden") && !options.prettySelect || field.parent().is(":hidden")))
524526
return false;
525527

@@ -668,6 +670,12 @@
668670
required = true;
669671
}
670672
break;
673+
case "funcCallRequired":
674+
errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._funcCallRequired);
675+
if (errorMsg !== undefined) {
676+
required = true;
677+
}
678+
break;
671679

672680
default:
673681
}
@@ -693,6 +701,14 @@
693701
break;
694702
}
695703
}
704+
705+
//funcCallRequired, first in rules, and has error, skip anything else
706+
if( i==0 && str.indexOf('funcCallRequired')==0 && errorMsg !== undefined ){
707+
promptText += errorMsg + "<br/>";
708+
options.isError=true;
709+
field_errors++;
710+
end_validation=true;
711+
}
696712

697713
// If it has been specified that validation should end now, break
698714
if (end_validation) {
@@ -803,7 +819,7 @@
803819
// Otherwise if we are doing a function call, make the call and return the object
804820
// that is passed back.
805821
var rule_index = jQuery.inArray(rule, rules);
806-
if (rule === "custom" || rule === "funcCall") {
822+
if (rule === "custom" || rule === "funcCall" || rule === "funcCallRequired") {
807823
var custom_validation_type = rules[rule_index + 1];
808824
rule = rule + "[" + custom_validation_type + "]";
809825
// Delete the rule from the rules array so that it doesn't try to call the
@@ -888,6 +904,7 @@
888904
"minCheckbox": "range-underflow",
889905
"equals": "pattern-mismatch",
890906
"funcCall": "custom-error",
907+
"funcCallRequired": "custom-error",
891908
"creditCard": "pattern-mismatch",
892909
"condRequired": "value-missing"
893910
},
@@ -1041,6 +1058,9 @@
10411058
return fn(field, rules, i, options);
10421059

10431060
},
1061+
_funcCallRequired: function(field, rules, i, options) {
1062+
return methods._funcCall(field,rules,i,options);
1063+
},
10441064
/**
10451065
* Field match
10461066
*
@@ -2002,8 +2022,10 @@
20022022
focusFirstField:true,
20032023
// Show prompts, set to false to disable prompts
20042024
showPrompts: true,
2005-
// Should we attempt to validate non-visible input fields contained in the form? (Useful in cases of tabbed containers, e.g. jQuery-UI tabs)
2006-
validateNonVisibleFields: false,
2025+
// Should we attempt to validate non-visible input fields contained in the form? (Useful in cases of tabbed containers, e.g. jQuery-UI tabs)
2026+
validateNonVisibleFields: false,
2027+
// ignore the validation for fields with this specific class (Useful in cases of tabbed containers AND hidden fields we don't want to validate)
2028+
ignoreFieldsWithClass: 'ignoreMe',
20072029
// Opening box position, possible locations are: topLeft,
20082030
// topRight, bottomLeft, centerRight, bottomRight, inline
20092031
// inline gets inserted after the validated field or into an element specified in data-prompt-target
@@ -2075,5 +2097,3 @@
20752097
}};
20762098
$(function(){$.validationEngine.defaults.promptPosition = methods.isRTL()?'topLeft':"topRight"});
20772099
})(jQuery);
2078-
2079-

0 commit comments

Comments
 (0)