Not able to mandate a field in child table for specific row [Solved]

Hi,

I want few fields of that particular row becomes mandatory if a value of a child table fields becomes equal to a specific value:


frappe.ui.form.on("Sales Order Item","customized", function(frm, cdt, cdn) { 

var d =locals[cdt][cdn]
var item=frappe.get_doc(cdt,cdn);

if(d.customized == "Yes")
{
frm.get_docfield("items", "standard_customization").reqd = true;
}
else
{
frm.get_docfield("items", "standard_customization").reqd = flase;
}
});

Now, my requirement is, if user selects customized=Yes in a particular row then standard_customization field become mandatory for that particular row only, but it is becoming mandatory for every row in the table.

Is there is any way to do this?

Regards
Ruchin Sharma

I think currently there is no straight forward way to do this. But you can write a validation to check mandatory values for a specific row.

frappe.ui.form.on("Sales Order", "validate", function(frm, cdt, cdn) { 
	$.each(frm.doc.items || [], function(i, d) {
		if(d.customized == "Yes" && !d.standard_customization) {
			frappe.throw("Standard Customization is mandatory");
		}
	})
});
5 Likes

Hi @nabinhait
It worked for me perfectly, but the only issue I noticed with this script is,
when the error message comes, my save button becomes inactive.

Is there any way to resolve this issue?

Regards
Ruchin Sharma

Instead of using frappe.throw, try to use frappe.msgprint and in the next line validated = false;

1 Like

Hi @nabinhait
BTW, I already did it and is working fine.

And many thanks to your for your quick response.

Regards
Ruchin Sharma

1 Like