Last active
December 30, 2015 07:09
-
-
Save crueber/7794315 to your computer and use it in GitHub Desktop.
CoffeeScript version of angular directive from this blog: http://rogeralsing.com/2013/08/26/angularjs-directive-to-check-that-passwords-match-followup/#comment-4344
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
directive = -> | |
{ | |
restrict: 'A' | |
scope: true | |
require: 'ngModel' | |
link: (scope, elem, attrs, control) -> | |
control.$parsers.unshift (value) -> | |
clearTimeout scope.match_password_timeout if scope.match_password_timeout | |
if value != '' | |
is_valid = -> | |
e1 = value | |
e2 = scope[attrs.passwordMatch] | |
control.$setValidity 'match', e1 == e2 | |
scope.$apply() | |
scope.match_password_timeout = setTimeout is_valid, 600 | |
else | |
control.$setValidity('match', true) | |
} | |
app.directive 'passwordMatch', [ 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
directive = -> | |
{ | |
restrict: 'A' | |
scope: true | |
require: 'ngModel' | |
link: (scope, elem, attrs, control) -> | |
checker = -> | |
e1 = scope.$eval(attrs.ngModel) | |
e2 = scope.$eval(attrs.passwordMatch) | |
e1 == e2 | |
scope.$watch checker, (n) -> | |
control.$setValidity('unique', n) | |
} | |
app.directive 'passwordMatch', [ directive ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment