From 65ce529a04bc5ec9205db728480cd5c8473b498c Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 12:25:14 +0530 Subject: [PATCH] fix: front-end bug in 'customize_form.js', triggered by delete actions on child-tables (#26344) (#26644) * fix: Doctype Links not updating #26041 https://github.com/frappe/frappe/issues/26041 In refresh_field(fieldname, txt) function of grid_row.js, added the comments :- // the below if statement is added to factor in the exception when this.doc is undefined - // - after row removals via customize_form.js on links, actions and states child-tables if (this.doc) field.docname = this.doc.name; * fix: Doctype Links not updating frappe#26041 In customize_form.js :- defined parent and parenttype as local variables in the event functions for child tables links, actions and states * Revert "In customize_form.js :-" This reverts commit 6732f0aec4733490da46d7bd5cbedf239d13ec89. * fix: Doctype Links not updating #26041 * style: amended spacing as per 'prettier' in precommit * style: added comma after last event definitions in child doctype, as per 'prettier' in precommit (cherry picked from commit b9f48455be10b40ab53375d7aef9fbaac644aea6) Co-authored-by: Karan Wilson <48678570+karanwilson@users.noreply.github.com> --- .../doctype/customize_form/customize_form.js | 23 +++++++++++++++++++ frappe/public/js/frappe/form/grid_row.js | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/frappe/custom/doctype/customize_form/customize_form.js b/frappe/custom/doctype/customize_form/customize_form.js index c314dc97af..2d047d4c30 100644 --- a/frappe/custom/doctype/customize_form/customize_form.js +++ b/frappe/custom/doctype/customize_form/customize_form.js @@ -335,10 +335,14 @@ frappe.ui.form.on("Customize Form Field", { }, }); +let parenttype, parent; // used in the form events for the child tables: links, actions and states + // can't delete standard links frappe.ui.form.on("DocType Link", { before_links_remove: function (frm, doctype, name) { let row = frappe.get_doc(doctype, name); + parenttype = row.parenttype; // used in the event links_remove + parent = row.parent; // used in the event links_remove if (!(row.custom || row.__islocal)) { frappe.msgprint(__("Cannot delete standard link. You can hide it if you want")); throw "cannot delete standard link"; @@ -348,12 +352,19 @@ frappe.ui.form.on("DocType Link", { let f = frappe.model.get_doc(cdt, cdn); f.custom = 1; }, + links_remove: function (frm, doctype, name) { + // replicate the changed rows from the browser's copy of the parent doc to the current 'Customize Form' doc + let parent_doc = locals[parenttype][parent]; + frm.doc.links = parent_doc.links; + }, }); // can't delete standard actions frappe.ui.form.on("DocType Action", { before_actions_remove: function (frm, doctype, name) { let row = frappe.get_doc(doctype, name); + parenttype = row.parenttype; // used in the event actions_remove + parent = row.parent; // used in the event actions_remove if (!(row.custom || row.__islocal)) { frappe.msgprint(__("Cannot delete standard action. You can hide it if you want")); throw "cannot delete standard action"; @@ -363,12 +374,19 @@ frappe.ui.form.on("DocType Action", { let f = frappe.model.get_doc(cdt, cdn); f.custom = 1; }, + actions_remove: function (frm, doctype, name) { + // replicate the changed rows from the browser's copy of the parent doc to the current 'Customize Form' doc + let parent_doc = locals[parenttype][parent]; + frm.doc.actions = parent_doc.actions; + }, }); // can't delete standard states frappe.ui.form.on("DocType State", { before_states_remove: function (frm, doctype, name) { let row = frappe.get_doc(doctype, name); + parenttype = row.parenttype; // used in the event states_remove + parent = row.parent; // used in the event states_remove if (!(row.custom || row.__islocal)) { frappe.msgprint(__("Cannot delete standard document state.")); throw "cannot delete standard document state"; @@ -378,6 +396,11 @@ frappe.ui.form.on("DocType State", { let f = frappe.model.get_doc(cdt, cdn); f.custom = 1; }, + states_remove: function (frm, doctype, name) { + // replicate the changed rows from the browser's copy of the parent doc to the current 'Customize Form' doc + let parent_doc = locals[parenttype][parent]; + frm.doc.states = parent_doc.states; + }, }); frappe.customize_form.save_customization = function (frm) { diff --git a/frappe/public/js/frappe/form/grid_row.js b/frappe/public/js/frappe/form/grid_row.js index 96db33dddd..5c0a5cbe22 100644 --- a/frappe/public/js/frappe/form/grid_row.js +++ b/frappe/public/js/frappe/form/grid_row.js @@ -1442,7 +1442,9 @@ export default class GridRow { let field = this.on_grid_fields_dict[fieldname]; // reset field value if (field) { - field.docname = this.doc.name; + // the below if statement is added to factor in the exception when this.doc is undefined - + // - after row removals via customize_form.js on links, actions and states child-tables + if (this.doc) field.docname = this.doc.name; field.refresh(); }