Skip to content

Instantly share code, notes, and snippets.

@crueber
Last active December 30, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crueber/7794315 to your computer and use it in GitHub Desktop.
Save crueber/7794315 to your computer and use it in GitHub Desktop.
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 ]
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