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"
msgprint(msg);
throw msg;
return false;
}
})