(isNgForm)
| 24987 | * related scope, under this name. |
| 24988 | */ |
| 24989 | var formDirectiveFactory = function(isNgForm) { |
| 24990 | return ['$timeout', '$parse', function($timeout, $parse) { |
| 24991 | var formDirective = { |
| 24992 | name: 'form', |
| 24993 | restrict: isNgForm ? 'EAC' : 'E', |
| 24994 | require: ['form', '^^?form'], //first is the form's own ctrl, second is an optional parent form |
| 24995 | controller: FormController, |
| 24996 | compile: function ngFormCompile(formElement, attr) { |
| 24997 | // Setup initial state of the control |
| 24998 | formElement.addClass(PRISTINE_CLASS).addClass(VALID_CLASS); |
| 24999 | |
| 25000 | var nameAttr = attr.name ? 'name' : (isNgForm && attr.ngForm ? 'ngForm' : false); |
| 25001 | |
| 25002 | return { |
| 25003 | pre: function ngFormPreLink(scope, formElement, attr, ctrls) { |
| 25004 | var controller = ctrls[0]; |
| 25005 | |
| 25006 | // if `action` attr is not present on the form, prevent the default action (submission) |
| 25007 | if (!('action' in attr)) { |
| 25008 | // we can't use jq events because if a form is destroyed during submission the default |
| 25009 | // action is not prevented. see #1238 |
| 25010 | // |
| 25011 | // IE 9 is not affected because it doesn't fire a submit event and try to do a full |
| 25012 | // page reload if the form was destroyed by submission of the form via a click handler |
| 25013 | // on a button in the form. Looks like an IE9 specific bug. |
| 25014 | var handleFormSubmission = function(event) { |
| 25015 | scope.$apply(function() { |
| 25016 | controller.$commitViewValue(); |
| 25017 | controller.$setSubmitted(); |
| 25018 | }); |
| 25019 | |
| 25020 | event.preventDefault(); |
| 25021 | }; |
| 25022 | |
| 25023 | formElement[0].addEventListener('submit', handleFormSubmission); |
| 25024 | |
| 25025 | // unregister the preventDefault listener so that we don't not leak memory but in a |
| 25026 | // way that will achieve the prevention of the default action. |
| 25027 | formElement.on('$destroy', function() { |
| 25028 | $timeout(function() { |
| 25029 | formElement[0].removeEventListener('submit', handleFormSubmission); |
| 25030 | }, 0, false); |
| 25031 | }); |
| 25032 | } |
| 25033 | |
| 25034 | var parentFormCtrl = ctrls[1] || controller.$$parentForm; |
| 25035 | parentFormCtrl.$addControl(controller); |
| 25036 | |
| 25037 | var setter = nameAttr ? getSetter(controller.$name) : noop; |
| 25038 | |
| 25039 | if (nameAttr) { |
| 25040 | setter(scope, controller); |
| 25041 | attr.$observe(nameAttr, function(newValue) { |
| 25042 | if (controller.$name === newValue) return; |
| 25043 | setter(scope, undefined); |
| 25044 | controller.$$parentForm.$$renameControl(controller, newValue); |
| 25045 | setter = getSetter(controller.$name); |
| 25046 | setter(scope, controller); |
no test coverage detected