MCPcopy Create free account
hub / github.com/apache/cloudstack / formDirectiveFactory

Function formDirectiveFactory

tools/ngui/static/js/lib/angular.js:11060–11115  ·  view source on GitHub ↗
(isNgForm)

Source from the content-addressed store, hash-verified

11058 </doc:example>
11059 */
11060var formDirectiveFactory = function(isNgForm) {
11061 return ['$timeout', function($timeout) {
11062 var formDirective = {
11063 name: 'form',
11064 restrict: 'E',
11065 controller: FormController,
11066 compile: function() {
11067 return {
11068 pre: function(scope, formElement, attr, controller) {
11069 if (!attr.action) {
11070 // we can't use jq events because if a form is destroyed during submission the default
11071 // action is not prevented. see #1238
11072 //
11073 // IE 9 is not affected because it doesn't fire a submit event and try to do a full
11074 // page reload if the form was destroyed by submission of the form via a click handler
11075 // on a button in the form. Looks like an IE9 specific bug.
11076 var preventDefaultListener = function(event) {
11077 event.preventDefault
11078 ? event.preventDefault()
11079 : event.returnValue = false; // IE
11080 };
11081
11082 addEventListenerFn(formElement[0], 'submit', preventDefaultListener);
11083
11084 // unregister the preventDefault listener so that we don't not leak memory but in a
11085 // way that will achieve the prevention of the default action.
11086 formElement.bind('$destroy', function() {
11087 $timeout(function() {
11088 removeEventListenerFn(formElement[0], 'submit', preventDefaultListener);
11089 }, 0, false);
11090 });
11091 }
11092
11093 var parentFormCtrl = formElement.parent().controller('form'),
11094 alias = attr.name || attr.ngForm;
11095
11096 if (alias) {
11097 scope[alias] = controller;
11098 }
11099 if (parentFormCtrl) {
11100 formElement.bind('$destroy', function() {
11101 parentFormCtrl.$removeControl(controller);
11102 if (alias) {
11103 scope[alias] = undefined;
11104 }
11105 extend(controller, nullFormCtrl); //stop propagating child destruction handlers upwards
11106 });
11107 }
11108 }
11109 };
11110 }
11111 };
11112
11113 return isNgForm ? extend(copy(formDirective), {restrict: 'EAC'}) : formDirective;
11114 }];
11115};
11116
11117var formDirective = formDirectiveFactory();

Callers 1

angular.jsFile · 0.85

Calls 3

extendFunction · 0.85
parentMethod · 0.80
copyFunction · 0.70

Tested by

no test coverage detected