MCPcopy Index your code
hub / github.com/binux/qiandao / FormController

Function FormController

web/static/components/angularjs/angular.js:16073–16228  ·  view source on GitHub ↗
(element, attrs, $scope, $animate)

Source from the content-addressed store, hash-verified

16071//asks for $scope to fool the BC controller module
16072FormController.$inject = ['$element', '$attrs', '$scope', '$animate'];
16073function FormController(element, attrs, $scope, $animate) {
16074 var form = this,
16075 parentForm = element.parent().controller('form') || nullFormCtrl,
16076 invalidCount = 0, // used to easily determine if we are valid
16077 errors = form.$error = {},
16078 controls = [];
16079
16080 // init state
16081 form.$name = attrs.name || attrs.ngForm;
16082 form.$dirty = false;
16083 form.$pristine = true;
16084 form.$valid = true;
16085 form.$invalid = false;
16086
16087 parentForm.$addControl(form);
16088
16089 // Setup initial state of the control
16090 element.addClass(PRISTINE_CLASS);
16091 toggleValidCss(true);
16092
16093 // convenience method for easy toggling of classes
16094 function toggleValidCss(isValid, validationErrorKey) {
16095 validationErrorKey = validationErrorKey ? '-' + snake_case(validationErrorKey, '-') : '';
16096 $animate.removeClass(element, (isValid ? INVALID_CLASS : VALID_CLASS) + validationErrorKey);
16097 $animate.addClass(element, (isValid ? VALID_CLASS : INVALID_CLASS) + validationErrorKey);
16098 }
16099
16100 /**
16101 * @ngdoc method
16102 * @name form.FormController#$addControl
16103 *
16104 * @description
16105 * Register a control with the form.
16106 *
16107 * Input elements using ngModelController do this automatically when they are linked.
16108 */
16109 form.$addControl = function(control) {
16110 // Breaking change - before, inputs whose name was "hasOwnProperty" were quietly ignored
16111 // and not added to the scope. Now we throw an error.
16112 assertNotHasOwnProperty(control.$name, 'input');
16113 controls.push(control);
16114
16115 if (control.$name) {
16116 form[control.$name] = control;
16117 }
16118 };
16119
16120 /**
16121 * @ngdoc method
16122 * @name form.FormController#$removeControl
16123 *
16124 * @description
16125 * Deregister a control from the form.
16126 *
16127 * Input elements using ngModelController do this automatically when they are destroyed.
16128 */
16129 form.$removeControl = function(control) {
16130 if (control.$name && form[control.$name] === control) {

Callers

nothing calls this directly

Calls 5

toggleValidCssFunction · 0.85
assertNotHasOwnPropertyFunction · 0.85
forEachFunction · 0.85
arrayRemoveFunction · 0.85
includesFunction · 0.85

Tested by

no test coverage detected