Validate before workflow action changes

when i click in Request for Approval then dialogue comes but workflow State is already change to next state before running Yes and No dialogue option?
when user click yes then workflow state should change to the next state ? any idea ?

frappe.ui.form.on('Leave Application',  {
    before_workflow_action: async (frm) => {
        if (frm.selected_workflow_action === "Request for Approval"){
            frappe.confirm('Are you sure you want to proceed?',
                () => {
                    console.log('yes')
                }, () => {
                    console.log('no')
            })
        }
    }
});

Hi @Rehan_Ansari
Try this code I hope you will get the solution

frappe.ui.form.on('Leave Application', {
	refresh:function(frm) {
	    if (frm.doc.workflow_state === "Request for Approval"){
	        frappe.confirm('Are you sure you want to proceed?',
                () => {
                   frm.set_value('workflow_state', 'Approved')
                   frm.save()
                }, () => {
                console.log('no')
            })
	    }
	}
})

Thank You!

Hello @Rehan_Ansari

this helped me few months ago:

Jiri Sir

frappe.ui.form.on('Leave Application', {
    before_workflow_action: async (frm) => {
        if (frm.selected_workflow_action === "Close"){
            let promise = new Promise((resolve, reject) => {
                frappe.dom.unfreeze()
                frappe.confirm(
                    "<b>Are you sure you want to close?</b>",
                    () => resolve(), //Yes
                    () => reject() //No
                );
            });
            await promise.catch(() => frappe.throw());
        }
    },
});