Button shows only if the document is submitted

Hello there,

I want the button shows only if the doc.docstatus==1 ( submitted ) only
and not shown before that !
Is there any idea how to do it in js?

this is the custom button : 
frappe.ui.form.on("Sales Invoice", {

    refresh: function(frm) {
        frm.add_custom_button(__('Ready to send'), function () {
                    'docname': frm.doc.name
                callback: function(r){

Hello, Take a look at this erpnext/sales_order.js at 07ff956fd83431839e4a1bc4c3f8a8f7c923fea4 · frappe/erpnext · GitHub

Thank you! I found it finally!

Tbh I’m beginner in frappe, so do you know if I can also specify the permissions in js?

No worries. we all start from somewhere

For permissions, you can try frappe.user_roles it returns an array of the user’s roles

Thank u! I will try it.