From e112c71b86134fa850bcd0e2ff710ec2e835314f Mon Sep 17 00:00:00 2001 From: pratu16x7 Date: Tue, 27 Jun 2017 14:01:58 +0530 Subject: [PATCH] allow for cloning other children --- frappe/public/js/legacy/clientscriptAPI.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frappe/public/js/legacy/clientscriptAPI.js b/frappe/public/js/legacy/clientscriptAPI.js index 326f4e075f..fb02dc79fc 100644 --- a/frappe/public/js/legacy/clientscriptAPI.js +++ b/frappe/public/js/legacy/clientscriptAPI.js @@ -248,7 +248,16 @@ _f.Frm.prototype.clear_table = function(fieldname) { _f.Frm.prototype.add_child = function(fieldname, values) { var doc = frappe.model.add_child(this.doc, frappe.meta.get_docfield(this.doctype, fieldname).options, fieldname); if(values) { - $.extend(doc, values); + // Deep clone + var d = JSON.parse(JSON.stringify(values)); + + // Values of unique keys should not be overridden + var unique_keys = ["idx", "name"]; + unique_keys.map((key) => { + d[key] && delete d[key]; + }); + + $.extend(doc, d); } return doc; }