MCPcopy Index your code
hub / github.com/angular-ui/ui-grid / addSetValidityMethod

Function addSetValidityMethod

lib/test/angular/1.6.7/angular.js:23866–23951  ·  view source on GitHub ↗
(context)

Source from the content-addressed store, hash-verified

23864 instance.$$classCache[INVALID_CLASS] = !(instance.$$classCache[VALID_CLASS] = instance.$$element.hasClass(VALID_CLASS));
23865}
23866function addSetValidityMethod(context) {
23867 var clazz = context.clazz,
23868 set = context.set,
23869 unset = context.unset;
23870
23871 clazz.prototype.$setValidity = function(validationErrorKey, state, controller) {
23872 if (isUndefined(state)) {
23873 createAndSet(this, '$pending', validationErrorKey, controller);
23874 } else {
23875 unsetAndCleanup(this, '$pending', validationErrorKey, controller);
23876 }
23877 if (!isBoolean(state)) {
23878 unset(this.$error, validationErrorKey, controller);
23879 unset(this.$$success, validationErrorKey, controller);
23880 } else {
23881 if (state) {
23882 unset(this.$error, validationErrorKey, controller);
23883 set(this.$$success, validationErrorKey, controller);
23884 } else {
23885 set(this.$error, validationErrorKey, controller);
23886 unset(this.$$success, validationErrorKey, controller);
23887 }
23888 }
23889 if (this.$pending) {
23890 cachedToggleClass(this, PENDING_CLASS, true);
23891 this.$valid = this.$invalid = undefined;
23892 toggleValidationCss(this, '', null);
23893 } else {
23894 cachedToggleClass(this, PENDING_CLASS, false);
23895 this.$valid = isObjectEmpty(this.$error);
23896 this.$invalid = !this.$valid;
23897 toggleValidationCss(this, '', this.$valid);
23898 }
23899
23900 // re-read the state as the set/unset methods could have
23901 // combined state in this.$error[validationError] (used for forms),
23902 // where setting/unsetting only increments/decrements the value,
23903 // and does not replace it.
23904 var combinedState;
23905 if (this.$pending && this.$pending[validationErrorKey]) {
23906 combinedState = undefined;
23907 } else if (this.$error[validationErrorKey]) {
23908 combinedState = false;
23909 } else if (this.$$success[validationErrorKey]) {
23910 combinedState = true;
23911 } else {
23912 combinedState = null;
23913 }
23914
23915 toggleValidationCss(this, validationErrorKey, combinedState);
23916 this.$$parentForm.$setValidity(validationErrorKey, combinedState, this);
23917 };
23918
23919 function createAndSet(ctrl, name, value, controller) {
23920 if (!ctrl[name]) {
23921 ctrl[name] = {};
23922 }
23923 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