Hi,
I have a child table Drug Prescription inside the Patient Encounter doctype.
In this table, there is a field called medication_status with values like Booked, Dispensed, and Partially Dispensed.
My requirement:
- If
medication_statusis Dispensed or Partially Dispensed, that row should become read-only (i.e., user should not be able to edit the fields anymore). - If the status is Booked, the row should still be editable.
I tried overriding refresh and after_save with a function like this:
function disable_processed_rows(frm) {
let rows = frm.fields_dict["drug_prescription"]?.grid?.grid_rows;
if (!rows || !rows.length) return;
rows.forEach(row => {
let fields = ["medication", "dosage", "period", "dosage_form", "drug_code", "medication_status"];
if (row.doc.medication_status === "Dispensed" || row.doc.medication_status === "Partially Dispensed") {
fields.forEach(f => {
if (row.columns[f] && row.columns[f].df) {
row.columns[f].df.read_only = 1;
}
});
} else {
fields.forEach(f => {
if (row.columns[f] && row.columns[f].df) {
row.columns[f].df.read_only = 0;
}
});
}
});
}
The logic works partly, but the fields are still editable until I refresh the form.
Is there a proper way in Frappe to lock child table rows dynamically based on field value?
Any suggestions or best practices would be really helpful.