Skip to content

Commit 7ab98ed

Browse files
authored
External validator function
Add the possibility to have an external validator function by passing to the validator an expression. Such as : "$validators" : { "equalsEmail" : "mustBeEqual(modelValue, 'email')" }
1 parent b28c7ca commit 7ab98ed

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/directives/schema-validate.directive.js

+11
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ export default function(sfValidator, $parse, sfSelect, $interpolate) {
105105
// Check if our version of angular has validators, i.e. 1.3+
106106
if (form[attr] && ngModel[attr]) {
107107
angular.forEach(form[attr], function(fn, name) {
108+
if ( angular.isString(fn) ) {
109+
var fnName = fn;
110+
fn = function( modelValue, viewValue, model, form ) {
111+
return scope.evalExpr( fnName, {
112+
'modelValue': modelValue,
113+
'viewValue': viewValue,
114+
'model': model,
115+
'form': form
116+
});
117+
}
118+
}
108119
ngModel[attr][name] = function(modelValue, viewValue) {
109120
return fn(modelValue, viewValue, scope.model, form);
110121
};

0 commit comments

Comments
 (0)