Skip to content

Commit

Permalink
fix: front-end bug in 'customize_form.js', triggered by delete action…
Browse files Browse the repository at this point in the history
…s on child-tables (#26344)

* fix: Doctype Links not updating #26041
#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 #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 6732f0a.

* 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 b9f4845)
  • Loading branch information
karanwilson authored and mergify[bot] committed Jun 3, 2024
1 parent b193396 commit e53ab66
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 23 additions & 0 deletions frappe/custom/doctype/customize_form/customize_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,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";
Expand All @@ -306,12 +310,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";
Expand All @@ -321,12 +332,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";
Expand All @@ -336,6 +354,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.validate_fieldnames = async function (frm) {
Expand Down
4 changes: 3 additions & 1 deletion frappe/public/js/frappe/form/grid_row.js
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,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();
}

Expand Down

0 comments on commit e53ab66

Please sign in to comment.