Client Script: no method to halt the Save?

From https://frappeframework.com/docs/v13/user/en/api/form#, there seems to be no way to halt the script from Saving if I detected there is error in Form.

Any solution?

@charleslcso

Yes, there’s

frappe.ui.form.on('Sales Invoice', 'validate', frm => {
    if (frm.doc.customer === "The X Man's") {
        validated = false;
        frappe.throw(__("You can't make a sell to The X Man's!"))
    }
})
2 Likes

@charleslcso I think that you can also return a promise reject…

frappe.ui.form.on('Sales Invoice', 'validate', frm => {
    if (frm.doc.customer === "The X Man's") {
        validated = false;
        return Promise.Reject();
    }
})
frappe.ui.form.on('Sales Invoice', 'before_save', frm => {
    if (frm.doc.customer === "The X Man's") {
        validated = false;
        return Promise.Reject();
    }
})
1 Like