Validate field in a child table

How can I check/validate a field in a child doctype in javascript?

Use case: I have a field Highest Score in the parent doctype. I have a child doctype Scores with a raw_score field. How can I check or validate that the value of raw_score should not be more than the Highest Score field in the parent doctype. This is what I made. It show the error message but still the record is added in the child table grid. I do not want to save the record if the condition is not meet.

Any suggestion?

frappe.ui.form.on("Scores", "raw_score", function (doc, cdt, cdn) {
    var score = frappe.get_doc(cdt, cdn);

    if (score.value > cur_frm.doc.highest_score) {
        msg = "Score should not be greater than highest score"
        throw msg;
        return false;

you can add do remove your row of child table by following way after msgprint

cur_frm.fields_dict[CHILD TABLE NAME].grid.grid_rows[CHILD TABLE NAME.idx - 1].remove();

and i think return false and throw msg not require

@Nishant_Jariwala Nice solution. What if I do not want to close the modal window if condition is not meet? Would this possible?

@ccfiel i think you need to do custom code for this.
e.g. use blur event on “score” textbox after leave box just check your condition and if condition not matched then make it blank by using set value and throw msg of your error

@Nishant_Jariwala I see. This is the thing I do not like with javascripts heheheh :slight_smile: to cluttered :frowning: Thanks for the suggestion!