Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.