How to validate certain field if no value, it will not save and appear msgprint()

Guys currently I have custom doctype for general receipt.

I want to make validation if certain field has no value, it will not save and appear msgprint to set the value first. I don’t want to make it mandatory. Because i have fields that depends on status selected.

1 Like

You can use frappe.throw instead of frappe.msgprint which will not save the doctype.
By the way, where do you want to add the validation- to the client side or the server side?

Okay I never use frappe.throw. But I’ll try it later.
I want to add validation on the client side.
Here my code:

frappe.ui.form.on("General Receipt", "validate", function(frm) {
    if (frm.doc.status === "Received In") {
		if (frm.doc.total_need_to_pay <= frm.doc.payment) {
			msgprint("total need to pay must more than payment");

	if (frm.doc.status === "Sending Out") {
		if (frm.doc.payments === "") {
			msgprint("You must put your value for payment")

    if ( < get_today()) {
        msgprint("You can not select past date in From Date");
        validated = false;

// make a field read-only after saving
frappe.ui.form.on("General Receipt", {
    refresh: function(frm) {
    	// make calculation on the fields
    	var a = frm.doc.payments;
		var b = frm.doc.total_need_to_pay - frm.doc.payment;
		frm.set_value("total", a);
		frm.set_value("balance_need_to_pay", b);
		frm.refresh_field("balance_need_to_pay", "total");
	        // use the __islocal value of doc, to check if the doc is saved or not
	    frm.set_df_property("balance_need_to_pay", "read_only", frm.doc.__islocal ? 1 : 1);
		frm.set_df_property("total", "read_only", frm.doc.__islocal ? 1 : 1);

did it worked or not?