Skip to content

Instantly share code, notes, and snippets.

@ludflu
Created May 30, 2014 18:26
Show Gist options
  • Save ludflu/800aaa624b21d02f59e8 to your computer and use it in GitHub Desktop.
Save ludflu/800aaa624b21d02f59e8 to your computer and use it in GitHub Desktop.
window.rjm.app.rjmNgDirectives.directive "validateBigCommerce", [
() ->
require: 'ngModel'
restrict: 'A'
link: (scope, ele, attrs, controller) ->
# var initializing used to prevent error messages from
# showing right away.
initializing = true
scope.$watch attrs.ngModel, (value) ->
debugger
if not initializing
# Angular 1.0.x does not have a setPristine()/setDirty() method for individual form
# inputs. To avoid passing in the parent form, set pristine/dirty manually.
controller.$pristine = false
controller.$dirty = true
if value?
storehash = controller.getStoreHash(value)
if storehash?
controller.$setValidity('validateBigCommerce', true)
controller.$setValidity('required', true)
else
controller.$setValidity('validateBigCommerce', false)
initializing = false
scope.$watch attrs.resetValidity, (value) ->
controller.$setValidity('validateBigCommerce', true)
controller.$setValidity('required', false)
controller.$pristine = true
controller.$dirty = false
]
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment