(isNgForm)
| 18520 | * related scope, under this name. |
| 18521 | */ |
| 18522 | var formDirectiveFactory = function(isNgForm) { |
| 18523 | return ['$timeout', function($timeout) { |
| 18524 | var formDirective = { |
| 18525 | name: 'form', |
| 18526 | restrict: isNgForm ? 'EAC' : 'E', |
| 18527 | controller: FormController, |
| 18528 | compile: function ngFormCompile(formElement) { |
| 18529 | // Setup initial state of the control |
| 18530 | formElement.addClass(PRISTINE_CLASS).addClass(VALID_CLASS); |
| 18531 | |
| 18532 | return { |
| 18533 | pre: function ngFormPreLink(scope, formElement, attr, controller) { |
| 18534 | // if `action` attr is not present on the form, prevent the default action (submission) |
| 18535 | if (!('action' in attr)) { |
| 18536 | // we can't use jq events because if a form is destroyed during submission the default |
| 18537 | // action is not prevented. see #1238 |
| 18538 | // |
| 18539 | // IE 9 is not affected because it doesn't fire a submit event and try to do a full |
| 18540 | // page reload if the form was destroyed by submission of the form via a click handler |
| 18541 | // on a button in the form. Looks like an IE9 specific bug. |
| 18542 | var handleFormSubmission = function(event) { |
| 18543 | scope.$apply(function() { |
| 18544 | controller.$commitViewValue(); |
| 18545 | controller.$setSubmitted(); |
| 18546 | }); |
| 18547 | |
| 18548 | event.preventDefault(); |
| 18549 | }; |
| 18550 | |
| 18551 | addEventListenerFn(formElement[0], 'submit', handleFormSubmission); |
| 18552 | |
| 18553 | // unregister the preventDefault listener so that we don't not leak memory but in a |
| 18554 | // way that will achieve the prevention of the default action. |
| 18555 | formElement.on('$destroy', function() { |
| 18556 | $timeout(function() { |
| 18557 | removeEventListenerFn(formElement[0], 'submit', handleFormSubmission); |
| 18558 | }, 0, false); |
| 18559 | }); |
| 18560 | } |
| 18561 | |
| 18562 | var parentFormCtrl = controller.$$parentForm, |
| 18563 | alias = controller.$name; |
| 18564 | |
| 18565 | if (alias) { |
| 18566 | setter(scope, alias, controller, alias); |
| 18567 | attr.$observe(attr.name ? 'name' : 'ngForm', function(newValue) { |
| 18568 | if (alias === newValue) return; |
| 18569 | setter(scope, alias, undefined, alias); |
| 18570 | alias = newValue; |
| 18571 | setter(scope, alias, controller, alias); |
| 18572 | parentFormCtrl.$$renameControl(controller, alias); |
| 18573 | }); |
| 18574 | } |
| 18575 | formElement.on('$destroy', function() { |
| 18576 | parentFormCtrl.$removeControl(controller); |
| 18577 | if (alias) { |
| 18578 | setter(scope, alias, undefined, alias); |
| 18579 | } |
no test coverage detected