Skip to content

[Issue 769]: Fix retrieval of the correct Object during $destroy on elements within an Array #770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/directives/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down