(context)
| 21704 | |
| 21705 | // helper methods |
| 21706 | function addSetValidityMethod(context) { |
| 21707 | var ctrl = context.ctrl, |
| 21708 | $element = context.$element, |
| 21709 | classCache = {}, |
| 21710 | set = context.set, |
| 21711 | unset = context.unset, |
| 21712 | parentForm = context.parentForm, |
| 21713 | $animate = context.$animate; |
| 21714 | |
| 21715 | classCache[INVALID_CLASS] = !(classCache[VALID_CLASS] = $element.hasClass(VALID_CLASS)); |
| 21716 | |
| 21717 | ctrl.$setValidity = setValidity; |
| 21718 | |
| 21719 | function setValidity(validationErrorKey, state, options) { |
| 21720 | if (state === undefined) { |
| 21721 | createAndSet('$pending', validationErrorKey, options); |
| 21722 | } else { |
| 21723 | unsetAndCleanup('$pending', validationErrorKey, options); |
| 21724 | } |
| 21725 | if (!isBoolean(state)) { |
| 21726 | unset(ctrl.$error, validationErrorKey, options); |
| 21727 | unset(ctrl.$$success, validationErrorKey, options); |
| 21728 | } else { |
| 21729 | if (state) { |
| 21730 | unset(ctrl.$error, validationErrorKey, options); |
| 21731 | set(ctrl.$$success, validationErrorKey, options); |
| 21732 | } else { |
| 21733 | set(ctrl.$error, validationErrorKey, options); |
| 21734 | unset(ctrl.$$success, validationErrorKey, options); |
| 21735 | } |
| 21736 | } |
| 21737 | if (ctrl.$pending) { |
| 21738 | cachedToggleClass(PENDING_CLASS, true); |
| 21739 | ctrl.$valid = ctrl.$invalid = undefined; |
| 21740 | toggleValidationCss('', null); |
| 21741 | } else { |
| 21742 | cachedToggleClass(PENDING_CLASS, false); |
| 21743 | ctrl.$valid = isObjectEmpty(ctrl.$error); |
| 21744 | ctrl.$invalid = !ctrl.$valid; |
| 21745 | toggleValidationCss('', ctrl.$valid); |
| 21746 | } |
| 21747 | |
| 21748 | // re-read the state as the set/unset methods could have |
| 21749 | // combined state in ctrl.$error[validationError] (used for forms), |
| 21750 | // where setting/unsetting only increments/decrements the value, |
| 21751 | // and does not replace it. |
| 21752 | var combinedState; |
| 21753 | if (ctrl.$pending && ctrl.$pending[validationErrorKey]) { |
| 21754 | combinedState = undefined; |
| 21755 | } else if (ctrl.$error[validationErrorKey]) { |
| 21756 | combinedState = false; |
| 21757 | } else if (ctrl.$$success[validationErrorKey]) { |
| 21758 | combinedState = true; |
| 21759 | } else { |
| 21760 | combinedState = null; |
| 21761 | } |
| 21762 | toggleValidationCss(validationErrorKey, combinedState); |
| 21763 | parentForm.$setValidity(validationErrorKey, combinedState, ctrl); |
no outgoing calls
no test coverage detected