“I want to make the child table read-only based on the condition: if it’s the first row, it should not be read-only, but once the second row is added, the first row should become read-only. Similarly, when the third row is added, the first and second rows should become read-only.”
You can achieve this by setting the docstatus
of all saved child table records to 1
inside the refresh
function. After updating the records, you should also refresh the corresponding field to ensure the changes are reflected correctly in the UI.
Note: This approach will only work when you save the first record and then add the next one. Newly added records will not be affected until they are saved and the refresh function runs again.
Write this in Parent Table JS File
frappe.ui.form.on('Parent Table', {
refresh(frm) {
console.log(frm.fields_dict['Parent Table Link Field'].grid);
// Update docstatus for all existing child table rows
for (let row of frm.fields_dict['Parent Table Link Field'].grid.data) {
row.docstatus = 1;
}
// Refresh the child table field to reflect changes
frm.refresh_field("Parent Table Link Field");
}
});