Skip to content

Instantly share code, notes, and snippets.

@JArmando
Created November 19, 2014 13:45
Show Gist options
  • 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