@@ -2726,8 +2726,16 @@ return /******/ (function(modules) { // webpackBootstrap
27262726 value : true
27272727 } ) ;
27282728
2729+ var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) { return typeof obj ; } : function ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol ? "symbol" : typeof obj ; } ;
2730+
27292731 exports . default = function ( $parse , $compile , $http , $templateCache , $interpolate , $q , sfErrorMessage , sfPath , sfSelect ) {
27302732
2733+ var keyFormat = {
2734+ COMPLETE : '*' ,
2735+ PATH : 'string' ,
2736+ INDICES : 'number'
2737+ } ;
2738+
27312739 return {
27322740 restrict : 'AE' ,
27332741 replace : false ,
@@ -2761,21 +2769,58 @@ return /******/ (function(modules) { // webpackBootstrap
27612769 return scope . form && scope . form . notitle !== true && scope . form . title ;
27622770 } ;
27632771
2764- //Normalise names and ids
2765- scope . fieldId = function ( prependFormName , omitArrayIndexes ) {
2766- var key = scope . parentKey || [ ] ;
2767- if ( scope . form . key ) {
2768- if ( typeof key [ key . length - 1 ] === 'number' ) {
2769- var combinedKey = key . concat ( scope . form . key . slice ( - 1 ) ) ;
2770- var formName = prependFormName && formCtrl && formCtrl . $name ? formCtrl . $name : undefined ;
2771- return sfPath . name ( combinedKey , '-' , formName , omitArrayIndexes ) ;
2772+ scope . getKey = function ( requiredFormat ) {
2773+ var format = requiredFormat || keyFormat . COMPLETE ;
2774+ var key = scope . parentKey ? scope . parentKey . slice ( 0 , scope . parentKey . length - 1 ) : [ ] ;
2775+
2776+ if ( typeof scope . $index === 'number' ) {
2777+ key = key . concat ( scope . $index ) ;
2778+ } ;
2779+
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 ) ) ;
27722783 } else {
2773- var formName = prependFormName && formCtrl && formCtrl . $name ? formCtrl . $name : undefined ;
2774- return sfPath . name ( scope . form . key , '-' , formName , omitArrayIndexes ) ;
2784+ scope . completeKey = scope . form . key . slice ( ) ;
2785+ } ;
2786+ } ;
2787+
2788+ if ( ! Array . isArray ( scope . completeKey ) ) {
2789+ return undefined ;
2790+ } ;
2791+
2792+ if ( format === keyFormat . COMPLETE ) {
2793+ return scope . completeKey ;
2794+ } ;
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 ) ;
27752799 }
2800+ return output ;
2801+ } , [ ] ) ;
2802+ } ;
2803+ if ( scope . form . key ) scope . completeKey = scope . getKey ( ) ;
2804+
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+ } ;
2813+
2814+ //Normalise names and ids
2815+ scope . fieldId = function ( prependFormName , omitArrayIndexes ) {
2816+ var formName = prependFormName && formCtrl && formCtrl . $name ? formCtrl . $name : undefined ;
2817+ var key = scope . getKey ( ) ;
2818+
2819+ if ( Array . isArray ( key ) ) {
2820+ return sfPath . name ( key , '-' , formName , omitArrayIndexes ) ;
27762821 } else {
27772822 return '' ;
2778- }
2823+ } ;
27792824 } ;
27802825
27812826 scope . listToCheckboxValues = function ( list ) {
@@ -2954,16 +2999,18 @@ return /******/ (function(modules) { // webpackBootstrap
29542999 // Default behavior can be supplied as a globalOption, and behavior can be overridden
29553000 // in the form definition.
29563001 scope . $on ( '$destroy' , function ( ) {
3002+ var key = scope . getKey ( ) ;
3003+
29573004 // If the entire schema form is destroyed we don't touch the model
29583005 if ( ! scope . externalDestructionInProgress ) {
29593006 var destroyStrategy = form . destroyStrategy || scope . options && scope . options . destroyStrategy || 'remove' ;
29603007 // No key no model, and we might have strategy 'retain'
2961- if ( form . key && destroyStrategy !== 'retain' ) {
3008+ if ( key && destroyStrategy !== 'retain' ) {
29623009
29633010 // Get the object that has the property we wan't to clear.
29643011 var obj = scope . model ;
2965- if ( form . key . length > 1 ) {
2966- obj = sfSelect ( form . key . slice ( 0 , form . key . length - 1 ) , obj ) ;
3012+ if ( key . length > 1 ) {
3013+ obj = sfSelect ( key . slice ( 0 , key . length - 1 ) , obj ) ;
29673014 }
29683015
29693016 // We can get undefined here if the form hasn't been filled out entirely
@@ -2975,17 +3022,17 @@ return /******/ (function(modules) { // webpackBootstrap
29753022 var type = form . schema && form . schema . type || '' ;
29763023
29773024 // Empty means '',{} and [] for appropriate types and undefined for the rest
2978- //console.log('destroy', destroyStrategy, form. key, type, obj);
3025+ //console.log('destroy', destroyStrategy, key, type, obj);
29793026 if ( destroyStrategy === 'empty' && type . indexOf ( 'string' ) !== - 1 ) {
2980- obj [ form . key . slice ( - 1 ) ] = '' ;
3027+ obj [ key . slice ( - 1 ) ] = '' ;
29813028 } else if ( destroyStrategy === 'empty' && type . indexOf ( 'object' ) !== - 1 ) {
2982- obj [ form . key . slice ( - 1 ) ] = { } ;
3029+ obj [ key . slice ( - 1 ) ] = { } ;
29833030 } else if ( destroyStrategy === 'empty' && type . indexOf ( 'array' ) !== - 1 ) {
2984- obj [ form . key . slice ( - 1 ) ] = [ ] ;
3031+ obj [ key . slice ( - 1 ) ] = [ ] ;
29853032 } else if ( destroyStrategy === 'null' ) {
2986- obj [ form . key . slice ( - 1 ) ] = null ;
3033+ obj [ key . slice ( - 1 ) ] = null ;
29873034 } else {
2988- delete obj [ form . key . slice ( - 1 ) ] ;
3035+ delete obj [ key . slice ( - 1 ) ] ;
29893036 }
29903037 }
29913038 }
@@ -3126,7 +3173,7 @@ return /******/ (function(modules) { // webpackBootstrap
31263173 return {
31273174 scope : true ,
31283175 controller : [ '$scope' , function SFArrayController ( $scope ) {
3129- this . key = $scope . form && $scope . form . key ? $scope . form . key : [ ] ;
3176+ this . key = $scope . form && $scope . form . key ? $scope . form . key . splice ( 0 , - 2 ) : [ ] ;
31303177 } ] ,
31313178 link : function link ( scope , element , attrs ) {
31323179 scope . min = 0 ;
@@ -3392,14 +3439,6 @@ return /******/ (function(modules) { // webpackBootstrap
33923439 scope . arrayIndices = scope . arrayIndices || [ ] ;
33933440 scope . arrayIndices = scope . arrayIndices . concat ( scope . arrayIndex ) ;
33943441 scope . $i = scope . arrayIndices ;
3395- scope . path = function ( modelPath ) {
3396- var i = - 1 ;
3397- modelPath = modelPath . replace ( / \[ \] / gi, function ( matched ) {
3398- i ++ ;
3399- return scope . $i [ i ] ;
3400- } ) ;
3401- return modelPath ;
3402- } ;
34033442 }
34043443 } ;
34053444 } ;
0 commit comments