@@ -31,10 +31,10 @@ var nullFormCtrl = {
3131 * of `FormController`.
3232 *
3333 */
34- FormController . $inject = [ 'name' , ' $element', '$attrs' ] ;
35- function FormController ( name , element , attrs ) {
34+ FormController . $inject = [ '$element' , '$attrs' ] ;
35+ function FormController ( element , attrs ) {
3636 var form = this ,
37- parentForm = element . parent ( ) . inheritedData ( '$formController ') || nullFormCtrl ,
37+ parentForm = element . parent ( ) . controller ( 'form ') || nullFormCtrl ,
3838 invalidCount = 0 , // used to easily determine if we are valid
3939 errors = form . $error = { } ;
4040
@@ -45,9 +45,6 @@ function FormController(name, element, attrs) {
4545 form . $valid = true ;
4646 form . $invalid = false ;
4747
48- // publish the form into scope
49- name ( this ) ;
50-
5148 parentForm . $addControl ( form ) ;
5249
5350 // Setup initial state of the control
@@ -130,9 +127,24 @@ function FormController(name, element, attrs) {
130127
131128
132129/**
130+ * @ngdoc directive
131+ * @name angular.module.ng.$compileProvider.directive.ng-form
132+ * @restrict EAC
133+ *
134+ * @description
135+ * Nestable alias of {@link angular.module.ng.$compileProvider.directive.form `form`} directive. HTML
136+ * does not allow nesting of form elements. It is useful to nest forms, for example if the validity of a
137+ * sub-group of controls needs to be determined.
138+ *
139+ * @param {string= } ng-form|name Name of the form. If specified, the form controller will be published into
140+ * related scope, under this name.
141+ *
142+ */
143+
144+ /**
133145 * @ngdoc directive
134146 * @name angular.module.ng.$compileProvider.directive.form
135- * @restrict EA
147+ * @restrict E
136148 *
137149 * @description
138150 * Directive that instantiates
@@ -141,12 +153,12 @@ function FormController(name, element, attrs) {
141153 * If `name` attribute is specified, the form controller is published onto the current scope under
142154 * this name.
143155 *
144- * # Alias: `ng-form`
156+ * # Alias: { @link angular.module.ng.$compileProvider.directive.ng-form `ng-form`}
145157 *
146158 * In angular forms can be nested. This means that the outer form is valid when all of the child
147159 * forms are valid as well. However browsers do not allow nesting of `<form>` elements, for this
148- * reason angular provides `<ng -form>` alias which behaves identical to `< form>` but allows
149- * element nesting.
160+ * reason angular provides { @link angular.module.ng.$compileProvider.directive.ng -form `ng- form`} alias
161+ * which behaves identical to `<form>` but allows form nesting.
150162 *
151163 *
152164 * # CSS classes
@@ -218,25 +230,31 @@ function FormController(name, element, attrs) {
218230 </doc:scenario>
219231 </doc:example>
220232 */
221- var formDirectiveDev = {
233+ var formDirectiveDir = {
222234 name : 'form' ,
223235 restrict : 'E' ,
224- inject : {
225- name : 'accessor'
226- } ,
227236 controller : FormController ,
228237 compile : function ( ) {
229238 return {
230239 pre : function ( scope , formElement , attr , controller ) {
231- formElement . bind ( 'submit' , function ( event ) {
232- if ( ! attr . action ) event . preventDefault ( ) ;
233- } ) ;
240+ if ( ! attr . action ) {
241+ formElement . bind ( 'submit' , function ( event ) {
242+ event . preventDefault ( ) ;
243+ } ) ;
244+ }
245+
246+ var parentFormCtrl = formElement . parent ( ) . controller ( 'form' ) ,
247+ alias = attr . name || attr . ngForm ;
234248
235- var parentFormCtrl = formElement . parent ( ) . inheritedData ( '$formController' ) ;
249+ if ( alias ) {
250+ scope [ alias ] = controller ;
251+ }
236252 if ( parentFormCtrl ) {
237253 formElement . bind ( '$destroy' , function ( ) {
238254 parentFormCtrl . $removeControl ( controller ) ;
239- if ( attr . name ) delete scope [ attr . name ] ;
255+ if ( alias ) {
256+ scope [ alias ] = undefined ;
257+ }
240258 extend ( controller , nullFormCtrl ) ; //stop propagating child destruction handlers upwards
241259 } ) ;
242260 }
@@ -245,5 +263,5 @@ var formDirectiveDev = {
245263 }
246264} ;
247265
248- var formDirective = valueFn ( formDirectiveDev ) ;
249- var ngFormDirective = valueFn ( extend ( copy ( formDirectiveDev ) , { restrict :'EAC' } ) ) ;
266+ var formDirective = valueFn ( formDirectiveDir ) ;
267+ var ngFormDirective = valueFn ( extend ( copy ( formDirectiveDir ) , { restrict : 'EAC' } ) ) ;
0 commit comments