Using below code, one can set child table field read only.
Syntax:
var df = frappe.meta.get_docfield("CHILD TABLE DOCTYPE", "FIELD NAME", cur_frm.doc.name);
df.read_only = 1;
example: Using this, we can set item_name
field read-only. This will helpful if you want to make fields read-only
based on some condition
frappe.ui.form.on("Sales Order","onload", function(frm, cdt, cdn) {
var df = frappe.meta.get_docfield("Sales Order Item","item_name", cur_frm.doc.name);
df.read_only = 1;
});
same solution also posted on my blog http://sbkolate.blogspot.in for reference
Thanks,
Sambhaji
14 Likes
rmehta
March 11, 2016, 9:57am
2
Nice
@kolate_sambhaji you can do with better formatting on your blog.
(e.g. code blocks should be easily readable)
Thanks a lot @kolate_sambhaji
This is the most simplest and efficient way to do it.
But I also wanted to add that, we need to refresh the fields.
So I used:
frm.refresh_fields();
Let me know, If I am missing anything here.
Happy to help,
Abhishek
2 Likes
This will make readonly child_table_field of all rows,but i want to make a perticular index row’s dfield as readonly.
Kindly give solution.
Regards,
Vishakha
1 Like
@kolate_sambhaji
I am also having this requirement right now.
Please provide your inputs here.
1 Like
sanjay
October 30, 2020, 5:42am
6
try below:
to make item child table readonly
setup: function(frm) {
frm.set_df_property(“items”, “read_only”, 1);
},
to make item fields readonly:
setup: function(frm) {
let item_toggle_fields = [‘item_code’, ‘item_group’, ‘brand’, ‘image’, ‘image_view’];
$.each(item_toggle_fields || , function(i, field) {
frm.fields_dict.items.grid.toggle_display(field, false);
});
},
1 Like
Hi, try this:
`const fieldname_arr = [‘source_warehouse’,‘int_address’,‘available_qty’,‘item’];
cur_frm.fields_dict['itemsaddr'].grid.grid_rows.forEach((grid_row)=> {
// check if is it sub-item (not group)
if (grid_row.doc.is_group === 0) {
grid_row.docfields.forEach((df)=>{
if (fieldname_arr.includes(df.fieldname)) {
df.bold=0; // remove bold text formatting
}
});
} else {
// if it is group
grid_row.docfields.forEach((df)=>{
if (fieldname_arr.includes(df.fieldname)) {
df.bold=1; //format the label in bold text
}
});
}
});
frm.refresh_field('itemsaddr');`
result:
1 Like
Sanjay’s example is for hiding field. Use the following to make it read only during ‘onload’ trigger.
frm.fields_dict.items.grid.update_docfield_property(field, "read_only", 1);
6 Likes
Great ! something I learnt new. Thank you.
That saves me after try a lot of codes and none of them works until i found your code. Thanks!