Hi,
I have set a field read only based on a validation in Child table. Issue is during setting the field validation_man to Invalid the fields are setting to read only. After that When I save the form and that, it is not readonly. But as attached code mentioned alerts are coming correctly.
frappe.ui.form.on(“RCA”, {
onload: function(frm) {
setTimeout(() => {
frm.doc.man.forEach(child => {
const grid_row = frm.fields_dict['man'].grid.grid_rows_by_docname[child.name];
if (grid_row) {
if (child.validation_man === "Invalid") {
alert(7)
grid_row.toggle_editable('action_plan_man', false);
grid_row.toggle_editable('corrective_action_man', false);
} else {
grid_row.toggle_editable('action_plan_man', true);
grid_row.toggle_editable('corrective_action_man', true);
}
}
});
}, 200);
},
onload_post_render: function(frm) {
setTimeout(() => {
frm.doc.man.forEach(child => {
const grid_row = frm.fields_dict['man'].grid.grid_rows_by_docname[child.name];
if (grid_row) {
if (child.validation_man === "Invalid") {
alert(9)
grid_row.toggle_editable('action_plan_man', false);
grid_row.toggle_editable('corrective_action_man', false);
} else {
grid_row.toggle_editable('action_plan_man', true);
grid_row.toggle_editable('corrective_action_man', true);
}
}
});
}, 200);
},
refresh: function(frm) {
setTimeout(() => {
frm.doc.man.forEach(child => {
const grid_row = frm.fields_dict['man'].grid.grid_rows_by_docname[child.name];
if (grid_row) {
if (child.validation_man === "Invalid") {
alert(5)
grid_row.toggle_editable('action_plan_man', false);
grid_row.toggle_editable('corrective_action_man', false);
} else {
grid_row.toggle_editable('action_plan_man', true);
grid_row.toggle_editable('corrective_action_man', true);
}
}
});
}, 200);
},
after_save: function(frm) {
frappe.set_route('List', 'RCA');
}
});
frappe.ui.form.on(‘Man’, {
validation_man: function(frm, cdt, cdn) {
let child = locals[cdt][cdn];
const grid_row = frm.fields_dict['man'].grid.grid_rows_by_docname[cdn];
if (child.validation_man === "Invalid") {
alert(3)
grid_row.toggle_editable('action_plan_man', false);
grid_row.toggle_editable('corrective_action_man', false);
} else {
grid_row.toggle_editable('action_plan_man', true);
grid_row.toggle_editable('corrective_action_man', true);
}
}
});
During setting the field to Invalid alert(3) is coming, then all other alerts during refresh, onload is working fine, but when I open the saved form it is not read only
is there an solution to it?