(element, attrs)
| 15130 | //asks for $scope to fool the BC controller module |
| 15131 | FormController.$inject = ['$element', '$attrs', '$scope']; |
| 15132 | function FormController(element, attrs) { |
| 15133 | var form = this, |
| 15134 | parentForm = element.parent().controller('form') || nullFormCtrl, |
| 15135 | invalidCount = 0, // used to easily determine if we are valid |
| 15136 | errors = form.$error = {}, |
| 15137 | controls = []; |
| 15138 | |
| 15139 | // init state |
| 15140 | form.$name = attrs.name || attrs.ngForm; |
| 15141 | form.$dirty = false; |
| 15142 | form.$pristine = true; |
| 15143 | form.$valid = true; |
| 15144 | form.$invalid = false; |
| 15145 | |
| 15146 | parentForm.$addControl(form); |
| 15147 | |
| 15148 | // Setup initial state of the control |
| 15149 | element.addClass(PRISTINE_CLASS); |
| 15150 | toggleValidCss(true); |
| 15151 | |
| 15152 | // convenience method for easy toggling of classes |
| 15153 | function toggleValidCss(isValid, validationErrorKey) { |
| 15154 | validationErrorKey = validationErrorKey ? '-' + snake_case(validationErrorKey, '-') : ''; |
| 15155 | element. |
| 15156 | removeClass((isValid ? INVALID_CLASS : VALID_CLASS) + validationErrorKey). |
| 15157 | addClass((isValid ? VALID_CLASS : INVALID_CLASS) + validationErrorKey); |
| 15158 | } |
| 15159 | |
| 15160 | /** |
| 15161 | * @ngdoc function |
| 15162 | * @name ng.directive:form.FormController#$addControl |
| 15163 | * @methodOf ng.directive:form.FormController |
| 15164 | * |
| 15165 | * @description |
| 15166 | * Register a control with the form. |
| 15167 | * |
| 15168 | * Input elements using ngModelController do this automatically when they are linked. |
| 15169 | */ |
| 15170 | form.$addControl = function(control) { |
| 15171 | // Breaking change - before, inputs whose name was "hasOwnProperty" were quietly ignored |
| 15172 | // and not added to the scope. Now we throw an error. |
| 15173 | assertNotHasOwnProperty(control.$name, 'input'); |
| 15174 | controls.push(control); |
| 15175 | |
| 15176 | if (control.$name) { |
| 15177 | form[control.$name] = control; |
| 15178 | } |
| 15179 | }; |
| 15180 | |
| 15181 | /** |
| 15182 | * @ngdoc function |
| 15183 | * @name ng.directive:form.FormController#$removeControl |
| 15184 | * @methodOf ng.directive:form.FormController |
| 15185 | * |
| 15186 | * @description |
| 15187 | * Deregister a control from the form. |
| 15188 | * |
| 15189 | * Input elements using ngModelController do this automatically when they are destroyed. |
nothing calls this directly
no test coverage detected
searching dependent graphs…