fix: enforce link_filters on link fields server-side

This commit is contained in:
Kaushal Shriwas 2026-02-26 17:53:57 +05:30
parent f12b5c081b
commit 3fd45ad05f
2 changed files with 12 additions and 1 deletions

View file

@ -465,7 +465,7 @@ def validate_link_and_fetch(
) )
if not search_result: if not search_result:
return {} # does not exist or filtered out return {}
values = None values = None
is_virtual_dt = bool(meta.get("is_virtual")) is_virtual_dt = bool(meta.get("is_virtual"))

View file

@ -870,6 +870,7 @@ frappe.ui.form.ControlLink = class ControlLink extends frappe.ui.form.ControlDat
validate_link_and_fetch(value) { validate_link_and_fetch(value) {
const args = this.get_search_args(value); const args = this.get_search_args(value);
if (!args) return; if (!args) return;
const has_filters = !!(args.filters && Object.keys(args.filters).length);
const columns_to_fetch = Object.values(this.fetch_map); const columns_to_fetch = Object.values(this.fetch_map);
@ -938,6 +939,16 @@ frappe.ui.form.ControlLink = class ControlLink extends frappe.ui.form.ControlDat
.then((response) => { .then((response) => {
if (!response) return; if (!response) return;
if (!response.name && has_filters) {
frappe.show_alert({
message: __("{0}: {1} did not match any results.", [
__(this.df.label || this.df.fieldname),
value,
]),
indicator: "red",
});
}
update_dependant_fields(response); update_dependant_fields(response);
return response.name; return response.name;
}); });