-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathdouble-validation.js
57 lines (49 loc) · 1.6 KB
/
double-validation.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
45
46
47
48
49
50
51
52
53
54
55
56
57
(function () {
'use strict';
angular.module('plunker', ['ae-datetimepicker'])
.controller('controller', [function () {
var vm = this;
vm.options = {
format: 'MM/DD/YYYY HH:mm',
useCurrent: false
};
}]);
angular
.module('plunker')
.directive('validateBefore', validateBefore);
angular
.module('plunker')
.directive('validateAfter', validateAfter);
function validateBefore() {
return {
restrict: 'A',
require: '?ngModel',
link: function ($scope, $element, $attrs, ngModel) {
ngModel.$validators.validateBefore = function (modelValue) {
var compareTo = $scope.$eval($attrs.validateBefore).$viewValue;
if (!!modelValue) {
return modelValue.isBefore(compareTo);
} else {
return true;
}
};
}
};
}
function validateAfter() {
return {
restrict: 'A',
require: '?ngModel',
link: function ($scope, $element, $attrs, ngModel) {
ngModel.$validators.validateAfter = function (modelValue) {
var compareTo = $scope.$eval($attrs.validateAfter).$viewValue;
if (!!modelValue) {
return modelValue.isAfter(compareTo);
} else {
return true;
}
};
}
};
}
})();