pyc-website
main website for pyc inc.
git clone https://9o.is/git/pyc-website.git
match.js
(760B)
1 /**
2 * Checks whether two inputs have matching values.
3 *
4 * Usage:
5 *
6 * <input name="input1" ng-model="model.password" type="password">
7 * <input name="input2" ng-model="model.confirm" type="password" data-match="model.password">
8 */
9 angular.module("match", [])
10 .directive('match', function () {
11 return {
12 require: 'ngModel',
13 restrict: 'A',
14 scope: {
15 match: '='
16 },
17 link: function(scope, elem, attrs, ctrl) {
18 scope.$watch(function() {
19 return (ctrl.$pristine && angular.isUndefined(ctrl.$modelValue)) || scope.match === ctrl.$modelValue;
20 }, function(currentValue) {
21 ctrl.$setValidity('match', currentValue);
22 });
23 }
24 };
25 });