Skip to content

Commit

Permalink
Merge pull request #15343 from sumaiya2908/empty-fetch-from-field
Browse files Browse the repository at this point in the history
fix: Clear fetched field when link field is cleared
  • Loading branch information
mergify[bot] committed Dec 22, 2021
2 parents 97cd221 + f8cbe95 commit d1e229d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions frappe/public/js/frappe/form/controls/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,7 @@ frappe.ui.form.ControlLink = class ControlLink extends frappe.ui.form.ControlDat
this.docname, value);
}
validate_link_and_fetch(df, options, docname, value) {
if (!value) return;

let field_value = "";
const fetch_map = this.fetch_map;
const columns_to_fetch = Object.values(fetch_map);

Expand All @@ -471,15 +470,16 @@ frappe.ui.form.ControlLink = class ControlLink extends frappe.ui.form.ControlDat
docname: value,
fields: columns_to_fetch,
}).then((response) => {
if (!response || !response.name) return null;
if (!docname || !columns_to_fetch.length) return response.name;

for (const [target_field, source_field] of Object.entries(fetch_map)) {
if (value) field_value = response[source_field];

frappe.model.set_value(
df.parent,
docname,
target_field,
response[source_field],
field_value,
df.fieldtype,
);
}
Expand Down

0 comments on commit d1e229d

Please sign in to comment.