blob: 253a6a646086a034a0ca7dd3a069161770b0666f (
plain)
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
|
window.angular && (function(angular) {
'use strict';
/**
* Password confirmation validator
*
* To use, add attribute directive to password confirmation input field
* Also include attribute 'first-password' with value set to first password
* to check against
*
* <input password-confirmation first-password="ctrl.password"
* name="passwordConfirm">
*
*/
angular.module('app.common.directives')
.directive('passwordConfirm', function() {
return {
restrict: 'A',
require: 'ngModel',
scope: {firstPassword: '='},
link: function(scope, element, attrs, controller) {
if (controller === undefined) {
return;
}
controller.$validators.passwordConfirm =
(modelValue, viewValue) => {
const firstPassword =
scope.firstPassword ? scope.firstPassword : '';
const secondPassword = modelValue || viewValue || '';
if (firstPassword == secondPassword) {
return true;
} else {
return false;
}
};
element.on('keyup', () => {
controller.$validate();
});
}
};
});
})(window.angular);
|