How to show frappe.confirm() before submitting the document?

Hey everyone,

I have a custom Doctype where there is a status field. If that status is “Rejected” it should show a confirmation message saying “are you sure you want reject this policy?”. If Yes is clicked than only this document should submit. How to achieve this?

Hi there,

This is what controller hooks are intended to do:


If you don’t have your doctype in an app, you can also achieve this with Server Scripts.

Edit: see below

I tried before_submit already but the document is getting submitted anyway with or without clicking Confirm button.

Sorry, I forgot that frappe.confirm is a client-side method. Because these are async methods, you need to treat the prompt as a promise that you await:

frappe.ui.form.on('Test Doctype', {
    before_submit: async (frm) => {
        let prompt = new Promise((resolve, reject) => {
                'Are you sure?',
                () => resolve(),
                () => reject()
        await prompt.then(
            () => frappe.show_alert("Submitted", 3), 
            () => {
                frappe.validated = false;
                frappe.show_alert("Not submitted", 3)

Thanks. It worked.

1 Like