Client Side Script Not Running After Submit

Why does this script not execute on submit?

frappe.ui.form.on('Purchase Invoice', {
	onsubmit: function(frm) {
	   console.log("Form submit event triggered");
	    frappe.msgprint("Triggered")
	}
})

I also tried using on_submit instead of onsubmit

Are you doing this on your custom app?

If yes, add this to a hook.

Example:

doctype_js = {
         "Purchase Invoice" : "YOUR_FILE_PATH"
}
frappe.ui.form.on('Purchase Invoice', {
	on_submit: function(frm) {
	   console.log("Form submit event triggered");
	    frappe.msgprint("Triggered")
	}
})

if u have add in client script then work fine and if u have override this js file then add in the hooks file like this

doctype_js = {
    "Purchase Invoice" : "public/js/purchase_invoice.js"
}
1 Like

I think you have to explore the form-events for a better understanding.

setup Triggered once when the form is created for the first time
before_load Triggered before the form is about to load
onload Triggered when the form is loaded and is about to render
refresh Triggered when the form is loaded and rendered.
onload_post_render Triggered after the form is loaded and rendered
validate Triggered before before_save
before_save Triggered before save is called
after_save Triggered after form is saved
before_submit Triggered before submit is called
on_submit Triggered after form is submitted
before_cancel Triggered before cancel is called
after_cancel Triggered after form is cancelled
before_discard Triggered before discard is called
after_discard Triggered after form is discarded
timeline_refresh Triggered after form timeline is rendered
{fieldname}_on_form_rendered Triggered when a row is opened as a form in a Table field
{fieldname} Triggered when the value of fieldname is changed
get_email_recipient_filters Called by the email dialog to fetch default filters for email recipients. Should accept two parameters frm (the current form) and field (“recipients”, “cc” or “bcc”), and return an array or dict of filters (related to the Contact doctype).
get_email_recipients Called by the email dialog to fetch default recipients. Should accept two parameters frm (the current form) and field (“recipients”, “cc” or “bcc”), and return a list of email addresses for this field.

Okay thanks guys. The hook worked