MCPcopy Create free account
hub / github.com/angular-ui/ui-router / addSetValidityMethod

Function addSetValidityMethod

test/angular/1.5/angular.js:28969–29061  ·  view source on GitHub ↗
(context)

Source from the content-addressed store, hash-verified

28967
28968// helper methods
28969function addSetValidityMethod(context) {
28970 var ctrl = context.ctrl,
28971 $element = context.$element,
28972 classCache = {},
28973 set = context.set,
28974 unset = context.unset,
28975 $animate = context.$animate;
28976
28977 classCache[INVALID_CLASS] = !(classCache[VALID_CLASS] = $element.hasClass(VALID_CLASS));
28978
28979 ctrl.$setValidity = setValidity;
28980
28981 function setValidity(validationErrorKey, state, controller) {
28982 if (isUndefined(state)) {
28983 createAndSet('$pending', validationErrorKey, controller);
28984 } else {
28985 unsetAndCleanup('$pending', validationErrorKey, controller);
28986 }
28987 if (!isBoolean(state)) {
28988 unset(ctrl.$error, validationErrorKey, controller);
28989 unset(ctrl.$$success, validationErrorKey, controller);
28990 } else {
28991 if (state) {
28992 unset(ctrl.$error, validationErrorKey, controller);
28993 set(ctrl.$$success, validationErrorKey, controller);
28994 } else {
28995 set(ctrl.$error, validationErrorKey, controller);
28996 unset(ctrl.$$success, validationErrorKey, controller);
28997 }
28998 }
28999 if (ctrl.$pending) {
29000 cachedToggleClass(PENDING_CLASS, true);
29001 ctrl.$valid = ctrl.$invalid = undefined;
29002 toggleValidationCss('', null);
29003 } else {
29004 cachedToggleClass(PENDING_CLASS, false);
29005 ctrl.$valid = isObjectEmpty(ctrl.$error);
29006 ctrl.$invalid = !ctrl.$valid;
29007 toggleValidationCss('', ctrl.$valid);
29008 }
29009
29010 // re-read the state as the set/unset methods could have
29011 // combined state in ctrl.$error[validationError] (used for forms),
29012 // where setting/unsetting only increments/decrements the value,
29013 // and does not replace it.
29014 var combinedState;
29015 if (ctrl.$pending && ctrl.$pending[validationErrorKey]) {
29016 combinedState = undefined;
29017 } else if (ctrl.$error[validationErrorKey]) {
29018 combinedState = false;
29019 } else if (ctrl.$$success[validationErrorKey]) {
29020 combinedState = true;
29021 } else {
29022 combinedState = null;
29023 }
29024
29025 toggleValidationCss(validationErrorKey, combinedState);
29026 ctrl.$$parentForm.$setValidity(validationErrorKey, combinedState, ctrl);

Callers 2

FormControllerFunction · 0.70
angular.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected