Skip to content

Commit

Permalink
fix(UX): reload form after renaming field (backport #25159) (#25160)
Browse files Browse the repository at this point in the history
* fix(UX): reload form after renaming field (#25159)

(cherry picked from commit af69dab)

# Conflicts:
#	frappe/custom/doctype/custom_field/custom_field.js

* chore: conflicts

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
  • Loading branch information
mergify[bot] and ankush committed Mar 3, 2024
1 parent 2718373 commit 6c7b4cd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
48 changes: 26 additions & 22 deletions frappe/custom/doctype/custom_field/custom_field.js
Expand Up @@ -112,28 +112,32 @@ frappe.ui.form.on("Custom Field", {
}
},
add_rename_field(frm) {
frm.add_custom_button(__("Rename Fieldname"), () => {
frappe.prompt(
{
fieldtype: "Data",
label: __("Fieldname"),
fieldname: "fieldname",
reqd: 1,
default: frm.doc.fieldname,
},
function (data) {
frappe.call({
method: "frappe.custom.doctype.custom_field.custom_field.rename_fieldname",
args: {
custom_field: frm.doc.name,
fieldname: data.fieldname,
},
});
},
__("Rename Fieldname"),
__("Rename")
);
});
if (!frm.is_new()) {
frm.add_custom_button(__("Rename Fieldname"), () => {
frappe.prompt(
{
fieldtype: "Data",
label: __("Fieldname"),
fieldname: "fieldname",
reqd: 1,
default: frm.doc.fieldname,
},
function (data) {
frappe
.xcall(
"frappe.custom.doctype.custom_field.custom_field.rename_fieldname",
{
custom_field: frm.doc.name,
fieldname: data.fieldname,
}
)
.then(() => frm.reload());
},
__("Rename Fieldname"),
__("Rename")
);
});
}
},
});

Expand Down
1 change: 1 addition & 0 deletions frappe/custom/doctype/custom_field/custom_field.py
Expand Up @@ -265,6 +265,7 @@ def rename_fieldname(custom_field: str, fieldname: str):
field.db_set("fieldname", field.fieldname, notify=True)
_update_fieldname_references(field, old_fieldname, new_fieldname)

frappe.msgprint(_("Custom field renamed to {0} successfully.").format(fieldname), alert=True)
frappe.db.commit()
frappe.clear_cache()

Expand Down

0 comments on commit 6c7b4cd

Please sign in to comment.