(element, attrs, $scope, $animate)
| 16311 | //asks for $scope to fool the BC controller module |
| 16312 | FormController.$inject = ['$element', '$attrs', '$scope', '$animate']; |
| 16313 | function FormController(element, attrs, $scope, $animate) { |
| 16314 | var form = this, |
| 16315 | parentForm = element.parent().controller('form') || nullFormCtrl, |
| 16316 | invalidCount = 0, // used to easily determine if we are valid |
| 16317 | errors = form.$error = {}, |
| 16318 | controls = []; |
| 16319 | |
| 16320 | // init state |
| 16321 | form.$name = attrs.name || attrs.ngForm; |
| 16322 | form.$dirty = false; |
| 16323 | form.$pristine = true; |
| 16324 | form.$valid = true; |
| 16325 | form.$invalid = false; |
| 16326 | |
| 16327 | parentForm.$addControl(form); |
| 16328 | |
| 16329 | // Setup initial state of the control |
| 16330 | element.addClass(PRISTINE_CLASS); |
| 16331 | toggleValidCss(true); |
| 16332 | |
| 16333 | // convenience method for easy toggling of classes |
| 16334 | function toggleValidCss(isValid, validationErrorKey) { |
| 16335 | validationErrorKey = validationErrorKey ? '-' + snake_case(validationErrorKey, '-') : ''; |
| 16336 | $animate.setClass(element, |
| 16337 | (isValid ? VALID_CLASS : INVALID_CLASS) + validationErrorKey, |
| 16338 | (isValid ? INVALID_CLASS : VALID_CLASS) + validationErrorKey); |
| 16339 | } |
| 16340 | |
| 16341 | /** |
| 16342 | * @ngdoc method |
| 16343 | * @name form.FormController#$addControl |
| 16344 | * |
| 16345 | * @description |
| 16346 | * Register a control with the form. |
| 16347 | * |
| 16348 | * Input elements using ngModelController do this automatically when they are linked. |
| 16349 | */ |
| 16350 | form.$addControl = function(control) { |
| 16351 | // Breaking change - before, inputs whose name was "hasOwnProperty" were quietly ignored |
| 16352 | // and not added to the scope. Now we throw an error. |
| 16353 | assertNotHasOwnProperty(control.$name, 'input'); |
| 16354 | controls.push(control); |
| 16355 | |
| 16356 | if (control.$name) { |
| 16357 | form[control.$name] = control; |
| 16358 | } |
| 16359 | }; |
| 16360 | |
| 16361 | /** |
| 16362 | * @ngdoc method |
| 16363 | * @name form.FormController#$removeControl |
| 16364 | * |
| 16365 | * @description |
| 16366 | * Deregister a control from the form. |
| 16367 | * |
| 16368 | * Input elements using ngModelController do this automatically when they are destroyed. |
| 16369 | */ |
| 16370 | form.$removeControl = function(control) { |
nothing calls this directly
no test coverage detected