MCPcopy Index your code
hub / github.com/angular-ui/ui-router / formDirectiveFactory

Function formDirectiveFactory

test/angular/1.2/angular.js:16633–16688  ·  view source on GitHub ↗
(isNgForm)

Source from the content-addressed store, hash-verified

16631 * related scope, under this name.
16632 */
16633var formDirectiveFactory = function(isNgForm) {
16634 return ['$timeout', function($timeout) {
16635 var formDirective = {
16636 name: 'form',
16637 restrict: isNgForm ? 'EAC' : 'E',
16638 controller: FormController,
16639 compile: function() {
16640 return {
16641 pre: function(scope, formElement, attr, controller) {
16642 if (!attr.action) {
16643 // we can't use jq events because if a form is destroyed during submission the default
16644 // action is not prevented. see #1238
16645 //
16646 // IE 9 is not affected because it doesn't fire a submit event and try to do a full
16647 // page reload if the form was destroyed by submission of the form via a click handler
16648 // on a button in the form. Looks like an IE9 specific bug.
16649 var preventDefaultListener = function(event) {
16650 event.preventDefault
16651 ? event.preventDefault()
16652 : event.returnValue = false; // IE
16653 };
16654
16655 addEventListenerFn(formElement[0], 'submit', preventDefaultListener);
16656
16657 // unregister the preventDefault listener so that we don't not leak memory but in a
16658 // way that will achieve the prevention of the default action.
16659 formElement.on('$destroy', function() {
16660 $timeout(function() {
16661 removeEventListenerFn(formElement[0], 'submit', preventDefaultListener);
16662 }, 0, false);
16663 });
16664 }
16665
16666 var parentFormCtrl = formElement.parent().controller('form'),
16667 alias = attr.name || attr.ngForm;
16668
16669 if (alias) {
16670 setter(scope, alias, controller, alias);
16671 }
16672 if (parentFormCtrl) {
16673 formElement.on('$destroy', function() {
16674 parentFormCtrl.$removeControl(controller);
16675 if (alias) {
16676 setter(scope, alias, undefined, alias);
16677 }
16678 extend(controller, nullFormCtrl); //stop propagating child destruction handlers upwards
16679 });
16680 }
16681 }
16682 };
16683 }
16684 };
16685
16686 return formDirective;
16687 }];
16688};
16689
16690var formDirective = formDirectiveFactory();

Callers 1

angular.jsFile · 0.70

Calls 4

setterFunction · 0.70
extendFunction · 0.70
addEventListenerFnFunction · 0.50
removeEventListenerFnFunction · 0.50

Tested by

no test coverage detected