How to Hide Button After Save button clicked

frappe.ui.form.on('Lead', {
    refresh(frm) {
   	setTimeout(() => {
          //  frm.remove_custom_button('Update Items');
            frm.remove_custom_button('Opportunity', 'Create');
          // frm.remove_custom_button('Opportunity', 'Create');
           frm.remove_custom_button('Quotation', 'Create');
         frm.remove_custom_button('Prospect', 'Create');
           frm.remove_custom_button('Add to Prospect', 'Action');
           // frm.remove_custom_button('Work Order', 'Make');
     },10);
    }
});

Above code is working only after I reload the form.

If you want a button when the doc in new then apply the condition:

if (!frm.is_new()) {

After the save, button will hide.

No. I want to hide “Create” and “Action” buttons, those are appearing when I click save button of “lead”.

frappe.ui.form.on('Lead', {
    refresh(frm) {
    setTimeout(() => {
        frm.remove_custom_button('Opportunity', 'Create');
         frm.remove_custom_button('Quotation', 'Create');
         frm.remove_custom_button('Prospect', 'Create');
          frm.remove_custom_button('Add to Prospect', 'Action');
        }, 10);
    }
});

Above code is working once I reload the page, After_Save event is not working.

I don’t understand your logic what are you trying to say?

Let’s assume the button will hide after save. But when you refresh the button will come back. You have to understand the logic. Without logic you cannot implement anything.

Plz check “Lead” Doctype, and apply above code. Then you will understand. I want to Hide those two buttons when I click save button instead of showing.

increase setTimeout time

10 → 50

Nothing happened.
setTimeout(() is under refresh(frm), So it will work on refresh event only.

Worked properly.

1 Like

Now after_save event is working. But once I refresh two button is showing again.

Please apply it.

frappe.ui.form.on('Lead', {
    after_save: function(frm) {
        hide_button(frm);
    },
    refresh: function(frm) {
        hide_button(frm);
    }
});

function hide_button(frm) {
    setTimeout(() => {
        frm.remove_custom_button('Opportunity', 'Create');
         frm.remove_custom_button('Quotation', 'Create');
         frm.remove_custom_button('Prospect', 'Create');
          frm.remove_custom_button('Add to Prospect', 'Action');
    }, 50);
}
1 Like

refresh was not working onload is working.

frappe.ui.form.on('Lead', {
    after_save: function(frm) {
      hide_button(frm);
    },
    
    onload: function(frm) {
        hide_button(frm);
    }
});

function hide_button(frm) {
    setTimeout(() => {
        frm.remove_custom_button('Opportunity', 'Create');
         frm.remove_custom_button('Quotation', 'Create');
         frm.remove_custom_button('Prospect', 'Create');
          frm.remove_custom_button('Add to Prospect', 'Action');
    },);
}

Thank you.

:thinking:

@Atheetha, Let me explain the difference between “onload” and “refresh” in simple terms.

Onload: This event triggers when you reload the page. However, if you open a record, go back to the list, and then open another record, sometime script might not work as expected, like hiding a button.

Refresh: This event triggers every time you open a document, ensuring the script runs. If it doesn’t work as expected, try increasing the setTimeout. In your case, “onload” might not be the best option.

You should understand form events before applying scripts. Simply adding a script won’t guarantee it works unless you understand how these events function.

Also check the differents in this video.

ok. I dont know why if I add “refresh”, “after_save” is not working.