Hello Team,
I’m trying to validate the doc just after making an API call and according the result I must decide if allow to save or not the doc.
My question is:
How can I prevent the doc to be saved after my callback. My API call is async, so I can’t prevent it, the doc will be saved anyway.
I share my code:
frappe.ui.form.on('Delivery Note', {
validate(frm) {
if(frm.doc.contact_tax_id == null || frm.doc.contact_tax_id === '') {
frappe.confirm('My question before continue...',
() => {
frappe.validated = true;
},
() => {
frappe.validated = false;
});
}
}
});
Thank you in advance.
You can use the async
param of frappe.call
if you are using it to do the api call and set it to false
. I don’t know if this can help you. I’m not seeing the call in your code.
Thank you @Nahuel_Nso.
Yes. It’s other code but same situation. I have to wait for user reply to decide if I will allow the doc to be saved or not, it’s a kind of callback.
You can use frappe.throw(__("ERROR"))
instead of frappe.validated = false;
But ERPNext won’t wait for my user callback. It will keep running, that’s why I’m not able to prevent the doc to be saved. If I throw an exc before the user’s reply then I won’t be able to allow the doc to be saved.
I will resume my problem with this code:
frappe.ui.form.on('Delivery Note', {
validate(frm) {
frappe.confirm('Would you like to take a final review?',
() => {
// Yes
// Allow the user to check again and cancel saving...
frappe.validated = false;
},
() => {
// No
// Go a save.
frappe.validated = true;
});
}
}
});
Then you should try to overwrite the primary action of the form. With something like cur_frm.page.set_primary_action
and invoque validate
or save
inside it.