diff --git a/frappe/public/js/frappe/form/controls/code.js b/frappe/public/js/frappe/form/controls/code.js
index f547c4c7e3..e710144b00 100644
--- a/frappe/public/js/frappe/form/controls/code.js
+++ b/frappe/public/js/frappe/form/controls/code.js
@@ -4,37 +4,37 @@ frappe.ui.form.ControlCode = class ControlCode extends frappe.ui.form.ControlTex
this.load_lib().then(() => this.make_ace_editor());
}
- make_wrapper() {
- super.make_wrapper();
- this.set_copy_button();
+ refresh() {
+ super.refresh();
+ if (this.df.fieldtype === "Code") {
+ // Don't show for derived classes
+ this.setup_copy_button();
+ }
}
- set_copy_button() {
- if (!this.frm?.doc) {
- return;
+ setup_copy_button() {
+ if (this.get_status() === "Write") {
+ this.copy_button?.remove();
+ this.copy_button = null;
+ return; // Don't show copy button in write mode
}
- const codeField = this.df.fieldtype === "Code";
- if ((codeField && this.df.read_only === 1) || (codeField && this.frm.doc.docstatus > 0)) {
- this.button = $(
- ``
- );
- this.button.on("click", () => {
- frappe.utils.copy_to_clipboard(
- frappe.model.get_value(this.doctype, this.docname, this.df.fieldname)
- );
- });
- this.button.appendTo(this.$wrapper);
- }
+ this.copy_button = $(
+ ``
+ );
+ this.copy_button.on("click", () => {
+ frappe.utils.copy_to_clipboard(this.get_model_value() || this.get_value());
+ });
+ this.copy_button.appendTo(this.$wrapper);
}
make_ace_editor() {