How to validate child's table field before saving?

I can validate fields in parent doc but below code is not working for child table. I want to validate the field in child table. Below script is throwing error message but while saving the document is being save. please help me with this.

frappe.ui.form.on(“Timesheet Detail”, “validate”, function(frm, cdt, cdn) {
var item = frappe.get_doc(cdt,cdn);
console.log(item);
if (item.status ===“Overdue”) {
frappe.throw(“Task is Overdue”);
}

Hello @niraj_regmi

Welcome to the Frappe / ERPNext community.

As far as I know, a child table does not have a validate event, only the parent does.

https://frappeframework.com/docs/v13/user/en/api/form

Although child documents -do- have the same controller methods as Parents, they are never called automatically, when you use the browser UI. This was an intentional design decision by the Framework authors.

The workaround is to edit the parent’s validate() function, and teach it to call the child document’s methods. For example:

class Timesheet(Document):

    def validate(self):
        for each_child_doc in self.time_logs:  # Timesheet Detail
            each_child_doc.validate()
1 Like