@@ -16,35 +16,23 @@ angular.module('angularUikit', [])
16
16
. directive ( 'ukNgSortable' , ukNgSortable )
17
17
. directive ( 'ukNgNotAllowArrayDuplicate' , ukNgNotAllowArrayDuplicate )
18
18
. directive ( 'hxSubmitOnEnter' , hxSubmitOnEnter )
19
- . directive ( 'isolateForm' , [ function ( ) {
19
+ . directive ( 'isolateForm' , function ( ) {
20
20
return {
21
- restrict : 'A' ,
22
- require : '?form' ,
23
- link : function ( scope , elm , attrs , ctrl ) {
24
- if ( ! ctrl ) {
25
- return ;
26
- }
27
-
28
- // Do a copy of the controller
29
- var ctrlCopy = { } ;
30
- angular . copy ( ctrl , ctrlCopy ) ;
31
-
32
- // Get the parent of the form
33
- var parent = elm . parent ( ) . controller ( 'form' ) ;
34
- // Remove parent link to the controller
35
- parent . $removeControl ( ctrl ) ;
36
-
37
- // Replace form controller with a "isolated form"
38
- ctrl . $setValidity = function ( validationToken , isValid , control ) {
39
- ctrlCopy . $setValidity ( validationToken , isValid , control ) ;
40
- parent . $setValidity ( validationToken , true , ctrl ) ;
41
- } ;
42
- ctrl . $setDirty = function ( ) {
43
- elm . removeClass ( 'ng-pristine' ) . addClass ( 'ng-dirty' ) ;
44
- ctrl . $dirty = true ;
45
- ctrl . $pristine = false ;
46
- } ;
21
+ restrict : 'A' ,
22
+ require : '?form' ,
23
+ link : function ( scope , element , attrs , formController ) {
24
+ if ( ! formController ) {
25
+ return ;
26
+ }
27
+
28
+ var parentForm = formController . $$parentForm ; // Note this uses private API
29
+ if ( ! parentForm ) {
30
+ return ;
47
31
}
32
+
33
+ // Remove this form from parent controller
34
+ parentForm . $removeControl ( formController ) ;
35
+ }
48
36
} ;
49
- } ] ) ;
37
+ } ) ;
50
38
;
0 commit comments