Last active
August 29, 2015 14:05
-
-
Save douglascorrea/d7e08f69fcbe16742da8 to your computer and use it in GitHub Desktop.
Password Confirmation AngularJS directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
How to use: | |
on inputs: | |
<input type="password" id="pw2" name="pw2" | |
ng-model="pw2" ng-required="" password-confirm="pw1" /> | |
get errors with: | |
"myForm.pw2.$error.passwordmatch" | |
*/ | |
angular.module('myApp') | |
.directive('passwordConfirm', [function () { | |
return { | |
require: 'ngModel', | |
link: function (scope, elem, attrs, ctrl) { | |
var me = attrs.ngModel; | |
var matchTo = attrs.passwordConfirm; | |
scope.$watch('[me, matchTo]', function(value){ | |
ctrl.$setValidity('passwordmatch', scope.$eval(me) === scope.$eval(matchTo) ); | |
}); | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment