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>
This commit is contained in:
mergify[bot] 2024-06-03 12:25:14 +05:30 committed by GitHub
parent b63295d25c
commit 65ce529a04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View file

@ -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) {

View file

@ -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();
}