MCPcopy
hub / github.com/angular-ui/ui-router / addSetValidityMethod

Function addSetValidityMethod

test/angular/1.7/angular.js:25081–25166  ·  view source on GitHub ↗
(context)

Source from the content-addressed store, hash-verified

25079 instance.$$classCache[INVALID_CLASS] = !(instance.$$classCache[VALID_CLASS] = instance.$$element.hasClass(VALID_CLASS));
25080}
25081function addSetValidityMethod(context) {
25082 var clazz = context.clazz,
25083 set = context.set,
25084 unset = context.unset;
25085
25086 clazz.prototype.$setValidity = function(validationErrorKey, state, controller) {
25087 if (isUndefined(state)) {
25088 createAndSet(this, '$pending', validationErrorKey, controller);
25089 } else {
25090 unsetAndCleanup(this, '$pending', validationErrorKey, controller);
25091 }
25092 if (!isBoolean(state)) {
25093 unset(this.$error, validationErrorKey, controller);
25094 unset(this.$$success, validationErrorKey, controller);
25095 } else {
25096 if (state) {
25097 unset(this.$error, validationErrorKey, controller);
25098 set(this.$$success, validationErrorKey, controller);
25099 } else {
25100 set(this.$error, validationErrorKey, controller);
25101 unset(this.$$success, validationErrorKey, controller);
25102 }
25103 }
25104 if (this.$pending) {
25105 cachedToggleClass(this, PENDING_CLASS, true);
25106 this.$valid = this.$invalid = undefined;
25107 toggleValidationCss(this, '', null);
25108 } else {
25109 cachedToggleClass(this, PENDING_CLASS, false);
25110 this.$valid = isObjectEmpty(this.$error);
25111 this.$invalid = !this.$valid;
25112 toggleValidationCss(this, '', this.$valid);
25113 }
25114
25115 // re-read the state as the set/unset methods could have
25116 // combined state in this.$error[validationError] (used for forms),
25117 // where setting/unsetting only increments/decrements the value,
25118 // and does not replace it.
25119 var combinedState;
25120 if (this.$pending && this.$pending[validationErrorKey]) {
25121 combinedState = undefined;
25122 } else if (this.$error[validationErrorKey]) {
25123 combinedState = false;
25124 } else if (this.$$success[validationErrorKey]) {
25125 combinedState = true;
25126 } else {
25127 combinedState = null;
25128 }
25129
25130 toggleValidationCss(this, validationErrorKey, combinedState);
25131 this.$$parentForm.$setValidity(validationErrorKey, combinedState, this);
25132 };
25133
25134 function createAndSet(ctrl, name, value, controller) {
25135 if (!ctrl[name]) {
25136 ctrl[name] = {};
25137 }
25138 set(ctrl[name], value, controller);

Callers 1

angular.jsFile · 0.70

Calls 7

isUndefinedFunction · 0.70
createAndSetFunction · 0.70
unsetAndCleanupFunction · 0.70
isBooleanFunction · 0.70
cachedToggleClassFunction · 0.70
toggleValidationCssFunction · 0.70
isObjectEmptyFunction · 0.70

Tested by

no test coverage detected