@@ -48,14 +48,23 @@ angular.module('schemaForm').directive('sfField',
48
48
} ;
49
49
50
50
scope . buttonClick = function ( $event , form ) {
51
+ var arrayDepth = form . key . filter ( function ( e ) { return e === '' } ) . length ;
52
+ var arrayIndices = ( arrayDepth > 1 ? Array ( arrayDepth - 1 ) . join ( '$parent.$parent.$parent.' ) + '$parent.$parent.$index,' : '' ) ;
53
+ for ( var i = arrayDepth ; i > 2 ; i -- ) {
54
+ arrayIndices += Array ( i - 1 ) . join ( '$parent.$parent.$parent.' ) + '$index,' ;
55
+ }
56
+ arrayIndices += '$index' ;
57
+ arrayIndices = scope . $eval ( '[' + arrayIndices + ']' ) ;
58
+
51
59
if ( angular . isFunction ( form . onClick ) ) {
52
- form . onClick ( $event , form ) ;
60
+
61
+ form . onClick ( $event , form , arrayIndices [ arrayDepth - 1 ] , arrayIndices ) ;
53
62
} else if ( angular . isString ( form . onClick ) ) {
54
63
if ( sfSchema ) {
55
64
//evaluating in scope outside of sfSchemas isolated scope
56
- sfSchema . evalInParentScope ( form . onClick , { '$event' : $event , form : form } ) ;
65
+ sfSchema . evalInParentScope ( form . onClick , { '$event' : $event , form : form , arrayIndex : arrayIndices [ arrayDepth - 1 ] , arrayIndices : arrayIndices } ) ;
57
66
} else {
58
- scope . $eval ( form . onClick , { '$event' : $event , form : form } ) ;
67
+ scope . $eval ( form . onClick , { '$event' : $event , form : form , arrayIndex : '$index' , arrayIndices : '[' + arrayIndices + ']' } ) ;
59
68
}
60
69
}
61
70
} ;
0 commit comments