Skip to content

Instantly share code, notes, and snippets.

@JArmando
Created November 19, 2014 13:45
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 JArmando/7538f67c2d671b46a767 to your computer and use it in GitHub Desktop.
Save JArmando/7538f67c2d671b46a767 to your computer and use it in GitHub Desktop.
A directive that allows displaying an invalid modelValue in angular and triggers validations
directives.directive 'displayInvalid', () ->
restrict: 'A',
require: 'ngModel',
link: (scope, elm, attrs, model) ->
displayed = false
scope.$watch attrs.ngModel, (newValue, oldValue, scope) ->
if displayed is false and oldValue isnt undefined
displayed = true
elm.val model.$modelValue
model.$setViewValue(model.$modelValue)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment