Validate my custom button


I want to validate my custom button like if my record is saved then and then my button will appear otherwise it is hidden in form view.

How to validate my button on this way?

Thank You.

You can get some hints from the examples displayed while writing custom script.

Here’s the example that will help you in this case:

// make a field read-only after saving
frappe.ui.form.on("Task", {
    refresh: function(frm) {
        // use the __islocal value of doc, to check if the doc is saved or not
        frm.set_df_property("myfield", "read_only", frm.doc.__islocal ? 0 : 1);

You can use the following flag for validating the button.
This will remain true if your form is unsaved. You can set ‘Display Depends On’ on this flag in order to view the button only if the form is unsaved


Try this,

if(!cur_frm.doc.__islocal) {
    	cur_frm.add_custom_button(__('Custom Button'),function() {})
1 Like

Thank You so much for help.