@@ -286,24 +286,18 @@ return /******/ (function(modules) { // webpackBootstrap
286286 }
287287 } ,
288288 condition : function condition ( args ) {
289+ var strKey = '' ;
290+ var strModel = 'undefined' ;
289291 // Do we have a condition? Then we slap on an ng-if on all children,
290292 // but be nice to existing ng-if.
291293 if ( args . form . condition ) {
292- var evalExpr = 'evalExpr(' + args . path + '.condition, { model: model, "arrayIndex": $index})' ;
293294 if ( args . form . key ) {
294- var strKey = sfPathProvider . stringify ( args . form . key ) ;
295- var arrayDepth = args . form . key . filter ( function ( e ) {
296- return e === '' ;
297- } ) . length ;
298- var arrayIndices = arrayDepth > 1 ? Array ( arrayDepth - 1 ) . join ( '$parent.$parent.$parent.' ) + '$parent.$parent.$index,' : '' ;
299- for ( var i = arrayDepth ; i > 2 ; i -- ) {
300- arrayIndices += Array ( i - 1 ) . join ( '$parent.$parent.$parent.' ) + '$index,' ;
301- }
302- arrayIndices += '$index' ;
303-
304- evalExpr = 'evalExpr(' + args . path + '.condition,{ model: model, "arrayIndex": $index, ' + '"arrayIndices": [' + arrayIndices + '],' + '"modelValue": model' + ( strKey [ 0 ] === '[' ? '' : '.' ) + strKey + '})' ;
295+ strKey = sfPathProvider . stringify ( args . form . key ) ;
296+ strModel = 'model' + ( strKey [ 0 ] === '[' ? '' : '.' ) + strKey ;
305297 }
306298
299+ var evalExpr = 'evalExpr(' + args . path + '.condition, { model: model, ' + '"arrayIndex": $index, ' + '"arrayIndices": arrayIndices, ' + '"path": path, ' + '"$i": $i, ' + '"$index": $index, ' + '"modelValue": ' + strModel + '})' ;
300+
307301 var children = args . fieldFrag . children || args . fieldFrag . childNodes ;
308302 for ( var i = 0 ; i < children . length ; i ++ ) {
309303 var child = children [ i ] ;
@@ -335,7 +329,7 @@ return /******/ (function(modules) { // webpackBootstrap
335329 state . modelName = 'item' ;
336330 }
337331
338- // Flag to the builder that where in an array.
332+ // Flag to the builder that we're in an array.
339333 // This is needed for compatabiliy if a "old" add-on is used that
340334 // hasn't been transitioned to the new builder.
341335 state . arrayCompatFlag = true ;
@@ -2702,7 +2696,15 @@ return /******/ (function(modules) { // webpackBootstrap
27022696 if ( _angular2 . default . isFunction ( form . onChange ) ) {
27032697 form . onChange ( ctrl . $modelValue , form ) ;
27042698 } else {
2705- scope . evalExpr ( form . onChange , { 'modelValue' : ctrl . $modelValue , form : form } ) ;
2699+ scope . evalExpr ( form . onChange , {
2700+ "modelValue" : ctrl . $modelValue ,
2701+ "form" : form ,
2702+ "arrayIndex" : scope . $index ,
2703+ "arrayIndices" : scope . arrayIndices ,
2704+ "path" : scope . path ,
2705+ "$i" : scope . $i ,
2706+ "$index" : scope . $index
2707+ } ) ;
27062708 }
27072709 } ) ;
27082710 }
@@ -2757,67 +2759,69 @@ return /******/ (function(modules) { // webpackBootstrap
27572759 } ) ;
27582760
27592761 // Fetch our form.
2760- scope . form = sfSchema . lookup [ 'f' + attrs . sfField ] ;
2762+ scope . initialForm = sfSchema . lookup [ 'f' + attrs . sfField ] ;
2763+ scope . form = _angular2 . default . copy ( sfSchema . lookup [ 'f' + attrs . sfField ] ) ;
27612764 } ,
27622765 post : function post ( scope , element , attrs , ctrl ) {
27632766 var sfSchema = ctrl [ 0 ] ;
27642767 var formCtrl = ctrl [ 1 ] ;
27652768 var keyCtrl = ctrl [ 2 ] ;
27662769
2767- //Keep error prone logic from the template
2768- scope . showTitle = function ( ) {
2769- return scope . form && scope . form . notitle !== true && scope . form . title ;
2770- } ;
2771-
27722770 scope . getKey = function ( requiredFormat ) {
27732771 var format = requiredFormat || keyFormat . COMPLETE ;
27742772 var key = scope . parentKey ? scope . parentKey . slice ( 0 , scope . parentKey . length - 1 ) : [ ] ;
27752773
2776- if ( typeof scope . $index === 'number' ) {
2777- key = key . concat ( scope . $index ) ;
2778- } ;
2774+ // Only calculate completeKey if not already saved to form.key
2775+ if ( scope . completeKey !== scope . form . key ) {
2776+ if ( typeof scope . $index === 'number' ) {
2777+ key = key . concat ( scope . $index ) ;
2778+ } ;
27792779
2780- if ( scope . form . key && scope . form . key . length ) {
2781- if ( typeof key [ key . length - 1 ] === 'number' && scope . form . key . length >= 1 ) {
2782- scope . completeKey = key . concat ( scope . form . key . slice ( - 1 ) ) ;
2783- } else {
2784- scope . completeKey = scope . form . key . slice ( ) ;
2780+ if ( scope . form . key && scope . form . key . length ) {
2781+ if ( typeof key [ key . length - 1 ] === 'number' && scope . form . key . length >= 1 ) {
2782+ scope . completeKey = key . concat ( scope . form . key . slice ( - 1 ) ) ;
2783+ } else {
2784+ scope . completeKey = scope . form . key . slice ( ) ;
2785+ } ;
27852786 } ;
27862787 } ;
27872788
2789+ // If there is no key then there's nothing to return
27882790 if ( ! Array . isArray ( scope . completeKey ) ) {
27892791 return undefined ;
27902792 } ;
27912793
2794+ // return the full key if not omiting any types via reduce
27922795 if ( format === keyFormat . COMPLETE ) {
27932796 return scope . completeKey ;
2797+ } else {
2798+ // else to clearly show that data must be ommited
2799+ return scope . completeKey . reduce ( function ( output , input , i ) {
2800+ if ( - 1 !== [ format ] . indexOf ( typeof input === 'undefined' ? 'undefined' : _typeof ( input ) ) ) {
2801+ return output . concat ( input ) ;
2802+ }
2803+ return output ;
2804+ } , [ ] ) ;
27942805 } ;
2795-
2796- return scope . completeKey . reduce ( function ( output , input , i ) {
2797- if ( - 1 !== [ format ] . indexOf ( typeof input === 'undefined' ? 'undefined' : _typeof ( input ) ) ) {
2798- return output . concat ( input ) ;
2799- }
2800- return output ;
2801- } , [ ] ) ;
28022806 } ;
2803- if ( scope . form . key ) scope . completeKey = scope . getKey ( ) ;
2807+ // Now that getKey is defined, run it! ...if there's a key.
2808+ if ( scope . form . key ) {
2809+ scope . form . key = scope . completeKey = scope . getKey ( ) ;
2810+ } ;
28042811
2805- scope . path = function ( modelPath ) {
2806- var i = - 1 ;
2807- modelPath = modelPath . replace ( / \[ \] / gi, function ( matched ) {
2808- i ++ ;
2809- return scope . $i [ i ] ;
2810- } ) ;
2811- return scope . $eval ( modelPath , scope ) ;
2812+ //Keep error prone logic from the template
2813+ scope . showTitle = function ( ) {
2814+ return scope . form && scope . form . notitle !== true && scope . form . title ;
28122815 } ;
28132816
28142817 //Normalise names and ids
28152818 scope . fieldId = function ( prependFormName , omitArrayIndexes ) {
2819+ var omit = omitArrayIndexes || false ;
28162820 var formName = prependFormName && formCtrl && formCtrl . $name ? formCtrl . $name : undefined ;
2817- var key = scope . getKey ( ) ;
2821+ var key = scope . completeKey ;
28182822
28192823 if ( Array . isArray ( key ) ) {
2820- return sfPath . name ( key , '-' , formName , omitArrayIndexes ) ;
2824+ return sfPath . name ( key , '-' , formName , omit ) ;
28212825 } else {
28222826 return '' ;
28232827 } ;
@@ -2943,7 +2947,7 @@ return /******/ (function(modules) { // webpackBootstrap
29432947
29442948 // append the field-id to the htmlClass
29452949 scope . form . htmlClass = scope . form . htmlClass || '' ;
2946- scope . form . htmlClass += ( scope . form . htmlClass ? ' ' : '' ) + scope . fieldId ( false , true ) ;
2950+ scope . form . htmlClass += ( scope . form . htmlClass ? ' ' : '' ) + scope . fieldId ( false ) + ' ' + scope . fieldId ( false , true ) ;
29472951
29482952 var form = scope . form ;
29492953
@@ -3428,17 +3432,30 @@ return /******/ (function(modules) { // webpackBootstrap
34283432 return {
34293433 scope : true ,
34303434 require : [ '^^sfNewArray' ] ,
3431- link : function link ( scope , element , attrs , ctrl ) {
3432- var currentKey = sfPath . parse ( attrs . sfParentKey ) ;
3433- if ( currentKey . length > 1 ) currentKey = currentKey . splice ( - 1 ) ;
3435+ controller : [ '$scope' , function SFKeyController ( $scope ) {
3436+ this . key = $scope . form && $scope . form . key ? $scope . form . key . splice ( 0 , - 2 ) : [ ] ;
3437+ } ] ,
3438+ link : {
3439+ pre : function pre ( scope , element , attrs , ctrl ) {
3440+ var currentKey = sfPath . parse ( attrs . sfParentKey ) ;
3441+ if ( currentKey . length > 1 ) currentKey = currentKey . splice ( - 1 ) ;
34343442
3435- scope . parentKey = scope . parentKey || [ ] ;
3436- scope . parentKey = scope . parentKey . concat ( currentKey , Number ( attrs . sfIndex ) ) ;
3443+ scope . parentKey = scope . parentKey || [ ] ;
3444+ scope . parentKey = scope . parentKey . concat ( currentKey , Number ( attrs . sfIndex ) ) ;
34373445
3438- scope . arrayIndex = Number ( attrs . sfIndex ) ;
3439- scope . arrayIndices = scope . arrayIndices || [ ] ;
3440- scope . arrayIndices = scope . arrayIndices . concat ( scope . arrayIndex ) ;
3441- scope . $i = scope . arrayIndices ;
3446+ scope . arrayIndex = Number ( attrs . sfIndex ) ;
3447+ scope . arrayIndices = scope . arrayIndices || [ ] ;
3448+ scope . arrayIndices = scope . arrayIndices . concat ( scope . arrayIndex ) ;
3449+ scope . $i = scope . arrayIndices ;
3450+ scope . path = function ( modelPath ) {
3451+ var i = - 1 ;
3452+ modelPath = modelPath . replace ( / \[ \] / gi, function ( matched ) {
3453+ i ++ ;
3454+ return '[' + scope . $i [ i ] + ']' ;
3455+ } ) ;
3456+ return scope . evalExpr ( modelPath , scope ) ;
3457+ } ;
3458+ }
34423459 }
34433460 } ;
34443461 } ;
0 commit comments