Validate = false

I wanna cancel the save document if the condition is true:

frappe.ui.form.on("Purchase Invoice", "validate", function(frm){
	valor_parcela = null
	$.each(frm.doc.parcelas || [], function(i, d) {
		valor_parcela = valor_parcela + d.valor_parcela
	if (valor_parcela != frm.doc.net_total) {
		frappe.msgprint("Total parcelas é diferente do valor da nota")
	        //Cancel the validate


frappe.validated = false;
1 Like

I’ll try, where can i see the events? I wanna change the validate for submit. Like:

frappe.ui.form.on(“Purchase Invoice”, submit_event, function(frm){}

validate function also called on submission of a document. So you can write the logic inside validate.
frappe.ui.form.on("Purchase Invoice", validate, function(frm){}

Can you give me an example using submit event please?

frappe.ui.form.on("Purchase Invoice", validate, function(frm){
  if(frm.doc.docstatus==1) {
    //write your logic here, it will be executed only on submit
   // in some conditions, set `frappe.validated = false;`

Validate is when i save the document, submit is when i submit… This is are different events…
I found submit event = “on_submit”, do you know what’s the cancel event?

validate is called on both save and submit events. I think if you use frappe.validated in on_submit it may not work.

There is a method called after_cancel which is called after cancellation.

Yeah, but submit is not called on validate… Cause this i used submit.
I wanna see all events of the erpnext form, how can i do this?
Thank you for help :slight_smile:

Thank you for reply, that’s worked!

You may try before_submit