Created
May 30, 2014 18:26
-
-
Save ludflu/800aaa624b21d02f59e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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