How can I create the "custom button" before the "primary action button"?

How can I create the “custom button” before the “primary action button”?
I have shown where I want to position it in the image.

There’s a couple of different techniques you can use for this.

It sounds like the set_secondary_action API is closest to what you’re describing.

If it doesn’t need to be next to the primary action use frm.add_custom_button(frm => {})

You can also disable save and supply your own primary action like this

There’s also an add_button API, but I don’t usually use it.

1 Like

Hi @gelveri,

Here I added a code of “Custom button” before the “primary action button”.
Please check it.

frappe.ui.form.on('Test DocType', {
	refresh: function(frm) {
		frm.page.set_secondary_action('Secondary Button'), function() {
		    // When this button is clicked, do this
		};
	}
});

Thank You!

2 Likes

Hi “NCP” thank you for this worked.

But when I make any change in the form, the button disappears. How can I overcome this?

https://streamable.com/e/gvlfs9?

My main goal is just to replace the default save button in this document with a new save button.

Through this button, if there is a change in a field on the form, I want to ask the user if he/she is sure to make a change and if he/she checks the I am sure option, I want to save it.

            frm.page.set_secondary_action('New Save Button'), function() {
                let docname = frm.docname; 
                let field_data = frm.doc.samplefield; 
                frappe.call({ //Python function that compares the data in the form with the data in the database and detects if there is a change.
                    method: 'erpnext.hr.doctype.bstest.events.denemeverisi',
                    args: {
                        'field_data': field_data,
                        'docname': docname
                    },
                    async: false,
                    callback: function(response) {
                        if (response.message === 'change') {
                            frappe.confirm(
                                'Sample Are u Sure message?',
                                () => {
                                    cur_frm.save(); 
                                },
                                () => {
                                    frappe.throw(__("bla bla bla"));
                                }
                            );
                        } else {
                            cur_frm.save();
                        }
                    }
                });
            }

so i think you have to check the @tmatteson post, which is provided in the above post. check and explore it.

Unfortunately, I couldn’t do it. Is there an example to guide me? Although I searched for “update_primary_action” in the forum, I can’t find any results.

Use it like

frm.page.set_primary_action('New Primary Button'), function() {
    // When this button is clicked, do this
};

It changes the main action that’s already set. I don’t know much about it, but you can try it.

1 Like

I don’t know if this is the best solution, but this is how I found a solution;


frappe.ui.form.on('bstest', {
    refresh: function(frm) {
        frm.disable_save();
        frm.page.set_secondary_action(__("Kaydet"), function(frm) {
            let docname = cur_frm.docname; 
            let deneme_data = cur_frm.doc.deneme; 
            frappe.call({ //Python function that compares the data in the form with the data in the database and detects if there is a change.
                method: 'erpnext.hr.doctype.bstest.events.denemeverisi',
                args: {
                    'yeniveri': deneme_data,
                    'docname': docname
                },
                async: false,
                callback: function(response) {
                    console.log(response.message)
                    if (response.message === 'veridegisti') {
                        frappe.confirm(
                            'Sample Are u Sure message?',
                            () => {
                                cur_frm.save(); 
                            },
                            () => {
                                frappe.throw(__("bla bla bla"));
                            }
                        );
                    } else {
                        cur_frm.save();
                    }
                }
        });
     } )},    
});