Skip to content

Commit 86d1087

Browse files
committed
Workaround to copy selected val of options
1 parent 97c0add commit 86d1087

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/collective/z3cform/datagridfield/static/datagridfield.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,14 @@ require([
175175
$(all_select2[i]).select2('destroy');
176176
}
177177
//clone the row
178-
var duplicatedRow = thisRow.clone();
178+
var duplicatedRow = thisRow.clone(true, true);
179+
// Jquery does not clone selected of options, so this is needed:
180+
// https://stackoverflow.com/questions/742810/clone-isnt-cloning-select-values
181+
var selects = $(thisRow).find("select");
182+
$(selects).each(function (i) {
183+
var select = this;
184+
$(duplicatedRow).find("select").eq(i).val($(select).val());
185+
});
179186
dgf.trigger("beforeaddrow", [dgf, duplicatedRow]);
180187

181188
// If using auto-append we add the "real" row before AA

0 commit comments

Comments
 (0)