From 6e36d9b40ff506d038f4c01d30deb046d130d3a1 Mon Sep 17 00:00:00 2001 From: Wei Wen Ho Date: Wed, 21 Sep 2016 11:29:47 +1000 Subject: [PATCH] [Issue 769]: Fix retrieval of the correct Object during $destroy on elements within an Array --- src/directives/field.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/directives/field.js b/src/directives/field.js index fcee48342..f012a4bb0 100644 --- a/src/directives/field.js +++ b/src/directives/field.js @@ -221,7 +221,17 @@ angular.module('schemaForm').directive('sfField', // Get the object that has the property we wan't to clear. var obj = scope.model; if (form.key.length > 1) { - obj = sfSelect(form.key.slice(0, form.key.length - 1), obj); + + // If form.key is an element of an Array, update it with the ArrayIndex so that sfSelect + // works correctly + if (form.key.indexOf('') !== -1) { + var updatedFormKey = form.key.map(function(v) { + return v === '' ? scope.$index : v; + }); + obj = sfSelect(updatedFormKey.slice(0, form.key.length - 1), obj); + } else { + obj = sfSelect(form.key.slice(0, form.key.length - 1), obj); + } } // We can get undefined here if the form hasn't been filled out entirely