Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')" }
  • Loading branch information
clmntr authored Sep 26, 2017
commit 7ab98edb0c0d3040bf4935ff6ce45ce38a2ae430
11 changes: 11 additions & 0 deletions src/directives/schema-validate.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ export default function(sfValidator, $parse, sfSelect, $interpolate) {
// Check if our version of angular has validators, i.e. 1.3+
if (form[attr] && ngModel[attr]) {
angular.forEach(form[attr], function(fn, name) {
if ( angular.isString(fn) ) {
var fnName = fn;
fn = function( modelValue, viewValue, model, form ) {
return scope.evalExpr( fnName, {
'modelValue': modelValue,
'viewValue': viewValue,
'model': model,
'form': form
});
}
}
ngModel[attr][name] = function(modelValue, viewValue) {
return fn(modelValue, viewValue, scope.model, form);
};
Expand Down