Repository: frappe/frappe
Pull request: fix(UX): Make fetch_from read_only if fetch_is_empty is not set
Fixes: https://github.com/frappe/frappe/issues/17457

Problem statement:
"Fetch from" UX
Very often users setup "fetch from" and then forget about it OR someone else notices weird behavior of "setting some field and seeing it get erased"

Probable solution:
- Disable user input on "fetch from" fields where "fetch only if empty" is not checked.
- Some icon to indicate that field will be fetched and user input is discarded

Hints from issue discussion:
@shariquerik can you please look into this?

Commit message: fix(UX): Make fetch_from read_only if fetch_is_empty is not set

Patch to review:
diff --git a/frappe/public/js/frappe/form/controls/base_input.js b/frappe/public/js/frappe/form/controls/base_input.js
index 62f1c51f6797..8c74f6e423d5 100644
--- a/frappe/public/js/frappe/form/controls/base_input.js
+++ b/frappe/public/js/frappe/form/controls/base_input.js
@@ -83,7 +83,9 @@ frappe.ui.form.ControlInput = class ControlInput extends frappe.ui.form.Control
 				me.value = me.doc[me.df.fieldname] || "";
 			}
 
-			if (me.can_write()) {
+			let is_fetch_from_read_only = me.df.fetch_from && !me.df.fetch_if_empty;
+
+			if (me.can_write() && !is_fetch_from_read_only) {
 				me.disp_area && $(me.disp_area).toggle(false);
 				$(me.input_area).toggle(true);
 				me.$input && me.$input.prop("disabled", false);
@@ -101,6 +103,16 @@ frappe.ui.form.ControlInput = class ControlInput extends frappe.ui.form.Control
 					}
 				}
 				me.$input && me.$input.prop("disabled", true);
+
+				if (is_fetch_from_read_only) {
+					$(me.disp_area).attr(
+						"title",
+						__(
+							"Its value is getting fetched from {0}'s {1} field",
+							me.df.fetch_from.split(".")
+						)
+					);
+				}
 			}
 
 			me.set_description();


Code review comments:
diff_hunk: @@ -101,6 +103,16 @@ frappe.ui.form.ControlInput = class ControlInput extends frappe.ui.form.Control
 					}
 				}
 				me.$input && me.$input.prop("disabled", true);
+
+				if (is_fetch_from_read_only) {
+					$(me.disp_area).attr(
+						"title",
+						__(
+							"Its value is getting fetched from {0}'s {1} field",
path: frappe/public/js/frappe/form/controls/base_input.js
text: @user1:
```suggestion
							"This value is fetched from {0}'s {1} field",
```

If we could do labels it would be great but that'd likely require fetching linked doctype's meta? :thinking: 

@author:
Yeah that's why i didn't do that