Skip to content

Commit 3c48c4f

Browse files
committed
sfNewArray: Change titleMapValue binding to prevent ngModel target array being cleared. Allows multiple checkboxes (array builder) controls to target the same ngModel target array.
1 parent 59e4e2c commit 3c48c4f

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/directives/newArray.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,12 @@ function(sel, sfPath, schemaForm) {
120120
if (vals && vals !== old) {
121121
var arr = getOrCreateModel();
122122

123-
// Apparently the fastest way to clear an array, readable too.
124-
// http://jsperf.com/array-destroy/32
125-
while (arr.length > 0) {
126-
arr.pop();
127-
}
128-
form.titleMap.forEach(function(item, index) {
129-
if (vals[index]) {
123+
form.titleMap.forEach(function (item, index) {
124+
var arrIndex = arr.indexOf(item.value);
125+
if (arrIndex === -1 && vals[index])
130126
arr.push(item.value);
131-
}
127+
if (arrIndex !== -1 && !vals[index])
128+
arr.splice(arrIndex, 1);
132129
});
133130

134131
// Time to validate the rebuilt array.

0 commit comments

Comments
 (0)