首页 > 解决方案 > Frappe: cur_frm.add_custom_button() does not add a Custom-Button

问题描述

I'm creating custom-buttons in a Client Script. This code works:

// Buttons do appear, everything is fine
frappe.ui.form.on('Article', {
    refresh(frm) {
        frm.add_custom_button("Hello", () => { 
            msgprint("Hello");
        }, "Greet");
        frm.add_custom_button("Ciao", () => { 
            msgprint("Ciao");
        }, "Greet");
}

Then I thought about creating the buttons outside the events with cur_frm, which doesn't work. Why is this so?

// Buttons don't appear
cur_frm.add_custom_button("Hello", () => { 
    msgprint("Hello");
}, "Greet");
cur_frm.add_custom_button("Ciao", () => { 
    msgprint("Ciao");
}, "Greet");

标签: frappeclientscript

解决方案


cur_frm is deprecated API. Why can't you use frm from one of the JS event methods?


推荐阅读