How to make child table field read only as per child table field condition whenever load

I am working with a Child Table, where the conditional statements work properly when I load a record into the child table. However, now I want to set a child table field as read-only. Please help.

frappe.ui.form.on("Asset List", {
  form_render(frm, cdt, cdn) {
    let child_doc = locals[cdt][cdn];
    let dispatchedStatus = child_doc.dispatched_status; 
    let fieldname = "dispatched_status"; 

if (dispatchedStatus !== "Pending") {
      console.log("Not pending");
//code here for read only child table field  "dispatched_status"

    } else {
      console.log("pending");
//code here for not read only child table field  "dispatched_status"
    }
  },
});

Why don’t you use depend on condition? Did you check by putting condition in depend on?

@NCP
In my scenario, I have an “asset_list” containing multiple items, each with a “dispatched_status” field. The requirement is that once an item is dispatched, its “dispatched_status” should not be editable again. The “dispatched_status” field is a Select field with options [Pending, Dispatch, Self-purchase].

If I go with “depends_on” and set it to eval:doc.dispatched_status=="Dispatch", the field becomes read-only or disabled. However, if a user intends to dispatch but suddenly decides to set it as “Self-purchase”, it won’t work. That’s why I want the “dispatched_status” field to be read-only whenever it is loaded.

Hi @Talib_Sheikh
Please try this code. I hope it will help you.

frappe.ui.form.on('Test Child', {
    status: function(frm, cdt, cdn) {
        let child_doc = locals[cdt][cdn];
        if (child_doc.status == "Pending") {
            frm.fields_dict['child_name'].grid.grid_rows_by_docname[cdn].toggle_editable('field_name', false);
        } else {
            frm.fields_dict['child_name'].grid.grid_rows_by_docname[cdn].toggle_editable('field_name', true);
        }
    }
});

Thank You!

3 Likes

@Mohammadali @NCP
thank you so much :star_struck: , now its perfectly working :100:

It makes complete column read only. Is it possible to make only that field read only in that row only?

1 Like

Have you found any solution to make field “read only” only for that filed not for whole column?