Skip to content

Commit 3def99c

Browse files
committed
Add funcCallRequired rule
funcCallRequired works as funcCall, but causes validation of the field to stop and display the returned error, this means that unlike funcCall, returning a string from the function causes the field to be required. See posabsolute#90
1 parent ab894c7 commit 3def99c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

js/jquery.validationEngine.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,12 @@
668668
required = true;
669669
}
670670
break;
671+
case "funcCallRequired":
672+
errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i, options, methods._funcCallRequired);
673+
if (errorMsg !== undefined) {
674+
required = true;
675+
}
676+
break;
671677

672678
default:
673679
}
@@ -693,6 +699,14 @@
693699
break;
694700
}
695701
}
702+
703+
//funcCallRequired, first in rules, and has error, skip anything else
704+
if( i==0 && str.indexOf('funcCallRequired')==0 && errorMsg !== undefined ){
705+
promptText += errorMsg + "<br/>";
706+
options.isError=true;
707+
field_errors++;
708+
end_validation=true;
709+
}
696710

697711
// If it has been specified that validation should end now, break
698712
if (end_validation) {
@@ -803,7 +817,7 @@
803817
// Otherwise if we are doing a function call, make the call and return the object
804818
// that is passed back.
805819
var rule_index = jQuery.inArray(rule, rules);
806-
if (rule === "custom" || rule === "funcCall") {
820+
if (rule === "custom" || rule === "funcCall" || rule === "funcCallRequired") {
807821
var custom_validation_type = rules[rule_index + 1];
808822
rule = rule + "[" + custom_validation_type + "]";
809823
// Delete the rule from the rules array so that it doesn't try to call the
@@ -888,6 +902,7 @@
888902
"minCheckbox": "range-underflow",
889903
"equals": "pattern-mismatch",
890904
"funcCall": "custom-error",
905+
"funcCallRequired": "custom-error",
891906
"creditCard": "pattern-mismatch",
892907
"condRequired": "value-missing"
893908
},
@@ -1041,6 +1056,9 @@
10411056
return fn(field, rules, i, options);
10421057

10431058
},
1059+
_funcCallRequired: function(field, rules, i, options) {
1060+
return methods._funcCall(field,rules,i,options);
1061+
},
10441062
/**
10451063
* Field match
10461064
*

0 commit comments

Comments
 (0)