@@ -94,29 +94,6 @@ describe('form', function() {
94
94
} ) ;
95
95
96
96
97
- it ( 'should chain nested forms' , function ( ) {
98
- doc = jqLite (
99
- '<ng:form name="parent">' +
100
- '<ng:form name="child">' +
101
- '<input ng:model="modelA" name="inputA">' +
102
- '</ng:form>' +
103
- '</ng:form>' ) ;
104
- $compile ( doc ) ( scope ) ;
105
-
106
- var parent = scope . parent ;
107
- var child = scope . child ;
108
- var input = child . inputA ;
109
-
110
- input . $setValidity ( 'MyError' , false ) ;
111
- expect ( parent . $error . MyError ) . toEqual ( [ child ] ) ;
112
- expect ( child . $error . MyError ) . toEqual ( [ input ] ) ;
113
-
114
- input . $setValidity ( 'MyError' , true ) ;
115
- expect ( parent . $error . MyError ) . toBeUndefined ( ) ;
116
- expect ( child . $error . MyError ) . toBeUndefined ( ) ;
117
- } ) ;
118
-
119
-
120
97
it ( 'should support two forms on a single scope' , function ( ) {
121
98
doc = $compile (
122
99
'<div>' +
@@ -152,38 +129,6 @@ describe('form', function() {
152
129
} ) ;
153
130
154
131
155
- it ( 'should chain nested forms in repeater' , function ( ) {
156
- doc = jqLite (
157
- '<ng:form name=parent>' +
158
- '<ng:form ng:repeat="f in forms" name=child>' +
159
- '<input type=text ng:model=text name=text>' +
160
- '</ng:form>' +
161
- '</ng:form>' ) ;
162
- $compile ( doc ) ( scope ) ;
163
-
164
- scope . $apply ( function ( ) {
165
- scope . forms = [ 1 ] ;
166
- } ) ;
167
-
168
- var parent = scope . parent ;
169
- var child = doc . find ( 'input' ) . scope ( ) . child ;
170
- var input = child . text ;
171
-
172
- expect ( parent ) . toBeDefined ( ) ;
173
- expect ( child ) . toBeDefined ( ) ;
174
- expect ( input ) . toBeDefined ( ) ;
175
-
176
- input . $setValidity ( 'myRule' , false ) ;
177
- expect ( input . $error . myRule ) . toEqual ( true ) ;
178
- expect ( child . $error . myRule ) . toEqual ( [ input ] ) ;
179
- expect ( parent . $error . myRule ) . toEqual ( [ child ] ) ;
180
-
181
- input . $setValidity ( 'myRule' , true ) ;
182
- expect ( parent . $error . myRule ) . toBeUndefined ( ) ;
183
- expect ( child . $error . myRule ) . toBeUndefined ( ) ;
184
- } ) ;
185
-
186
-
187
132
it ( 'should publish widgets' , function ( ) {
188
133
doc = jqLite ( '<form name="form"><input type="text" name="w1" ng-model="some" /></form>' ) ;
189
134
$compile ( doc ) ( scope ) ;
@@ -197,6 +142,93 @@ describe('form', function() {
197
142
} ) ;
198
143
199
144
145
+ describe ( 'nested forms' , function ( ) {
146
+
147
+ it ( 'should chain nested forms' , function ( ) {
148
+ doc = jqLite (
149
+ '<ng:form name="parent">' +
150
+ '<ng:form name="child">' +
151
+ '<input ng:model="modelA" name="inputA">' +
152
+ '<input ng:model="modelB" name="inputB">' +
153
+ '</ng:form>' +
154
+ '</ng:form>' ) ;
155
+ $compile ( doc ) ( scope ) ;
156
+
157
+ var parent = scope . parent ,
158
+ child = scope . child ,
159
+ inputA = child . inputA ,
160
+ inputB = child . inputB ;
161
+
162
+ inputA . $setValidity ( 'MyError' , false ) ;
163
+ inputB . $setValidity ( 'MyError' , false ) ;
164
+ expect ( parent . $error . MyError ) . toEqual ( [ child ] ) ;
165
+ expect ( child . $error . MyError ) . toEqual ( [ inputA , inputB ] ) ;
166
+
167
+ inputA . $setValidity ( 'MyError' , true ) ;
168
+ expect ( parent . $error . MyError ) . toEqual ( [ child ] ) ;
169
+ expect ( child . $error . MyError ) . toEqual ( [ inputB ] ) ;
170
+
171
+ inputB . $setValidity ( 'MyError' , true ) ;
172
+ expect ( parent . $error . MyError ) . toBeUndefined ( ) ;
173
+ expect ( child . $error . MyError ) . toBeUndefined ( ) ;
174
+ } ) ;
175
+
176
+
177
+ it ( 'should deregister a child form when its DOM is removed' , function ( ) {
178
+ doc = jqLite (
179
+ '<ng:form name="parent">' +
180
+ '<ng:form name="child">' +
181
+ '<input ng:model="modelA" name="inputA" required>' +
182
+ '</ng:form>' +
183
+ '</ng:form>' ) ;
184
+ $compile ( doc ) ( scope ) ;
185
+ scope . $apply ( ) ;
186
+
187
+ var parent = scope . parent ,
188
+ child = scope . child ;
189
+
190
+ expect ( parent . $error . required ) . toEqual ( [ child ] ) ;
191
+ doc . children ( ) . remove ( ) ; //remove child
192
+
193
+ expect ( parent . child ) . toBeUndefined ( ) ;
194
+ expect ( scope . child ) . toBeUndefined ( ) ;
195
+ expect ( parent . $error . required ) . toBeUndefined ( ) ;
196
+ } ) ;
197
+
198
+
199
+ it ( 'should chain nested forms in repeater' , function ( ) {
200
+ doc = jqLite (
201
+ '<ng:form name=parent>' +
202
+ '<ng:form ng:repeat="f in forms" name=child>' +
203
+ '<input type=text ng:model=text name=text>' +
204
+ '</ng:form>' +
205
+ '</ng:form>' ) ;
206
+ $compile ( doc ) ( scope ) ;
207
+
208
+ scope . $apply ( function ( ) {
209
+ scope . forms = [ 1 ] ;
210
+ } ) ;
211
+
212
+ var parent = scope . parent ;
213
+ var child = doc . find ( 'input' ) . scope ( ) . child ;
214
+ var input = child . text ;
215
+
216
+ expect ( parent ) . toBeDefined ( ) ;
217
+ expect ( child ) . toBeDefined ( ) ;
218
+ expect ( input ) . toBeDefined ( ) ;
219
+
220
+ input . $setValidity ( 'myRule' , false ) ;
221
+ expect ( input . $error . myRule ) . toEqual ( true ) ;
222
+ expect ( child . $error . myRule ) . toEqual ( [ input ] ) ;
223
+ expect ( parent . $error . myRule ) . toEqual ( [ child ] ) ;
224
+
225
+ input . $setValidity ( 'myRule' , true ) ;
226
+ expect ( parent . $error . myRule ) . toBeUndefined ( ) ;
227
+ expect ( child . $error . myRule ) . toBeUndefined ( ) ;
228
+ } ) ;
229
+ } )
230
+
231
+
200
232
describe ( 'validation' , function ( ) {
201
233
202
234
beforeEach ( function ( ) {
0 commit comments