overleaf/services/web/public/coffee/directives/equals.coffee
2014-07-08 12:02:26 +01:00

15 lines
356 B
CoffeeScript

define [
"base"
], (App) ->
App.directive 'equals', () ->
return {
require: "ngModel",
link: (scope, element, attrs, ngModel) ->
scope.$watch attrs.ngModel, () -> validate()
attrs.$observe 'equals', () -> validate()
validate = () ->
equal = (attrs.equals == ngModel.$viewValue)
ngModel.$setValidity('areEqual', equal)
}