-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathangular-jquery-validate.js
44 lines (42 loc) · 1.24 KB
/
angular-jquery-validate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
angular.module('angular-jquery-validate', []).factory('jqueryValidate', [function () {
return $.validator;
}]).provider('$jqueryValidate', function () {
return {
setDefaults: function (options) {
$.validator.setDefaults(options);
},
addMethod: function (name, func, errorText) {
$.validator.addMethod(name, func, errorText);
},
$get: function () {
return {
}
}
}
}).directive('formvalidator', function () {
return {
restrict: 'A',
scope: {
formvalidatorconfig: '=',
formvalidatorapi: '='
},
link: function (scope, elem, attr, ctrl) {
scope.$watch('formvalidatorconfig', function (value) {
if (value) {
elem.validate(value);
if (value.validateOnInit)
scope.formvalidatorapi.validate();
}
});
scope.formvalidatorapi = {
validate: function() {
elem.validate().form();
},
valid: function () {
return elem.valid();
}
};
}
};
});