How to change set_df_property in Child Table Field

Hello,

I want to make a child table field Required True to Required False.

In Parent table i am using cur_frm.set_df_property(“group”, “hidden”, false); But how can i implement this in child table.

Bump~~

I also need this

I did something similar recently.

Remember this will not effect server side validation. Hope this helps

1 Like

try

cur_frm.get_field("fields").grid.toggle_reqd("fieldname", true);
6 Likes

thanks @jvermette and @rmehta. But both these solutions change the property for the entire rows.
Cant i change the property for a single row in child table based upon a select or checkbox in the same child row?

Hello,

I am trying to do the same but instead of making field required, I am making field read only. I tried the method.

cur_frm.get_field(“fields”).grid.toggle_enable(“fieldname”, true);

but got the following error:

Uncaught TypeError: cur_frm.get_field(…).grid.toggle_enable is not a function

I also found the following method :

cur_frm.get_field(“fieldname”).grid.docfields[index].read_only = 1

The above code works and it makes the field read only. But I am not sure that passing the index is right approach to do this. Is their any workaround.

Thanks,
Makarand Bauskar

cur_frm.get_field("fieldname").grid.fieldinfo["child_fieldname"].read_only = 1

if fieldinfo of the child fieldname does not exist, then create an empty dict.

Hi,

cur_frm.get_field(“fieldname”).grid.fieldinfo[“child_fieldname”] = {}
aslo tried
cur_frm.get_field(“fieldname”).grid.fieldinfo = {“child_fieldname”:{}}

cur_frm.get_field(“fieldname”).grid.fieldinfo[“child_fieldname”].read_only = 1

I tried to set the read_only property to fieldinfo also created the empty dict if fieldname does not exist. But no success.

Thanks,
Makarand Bauskar

Sorry my mistake. Was confusing with get_query

use this:

frappe.meta.get_docfield(this.doctype, fieldname, this.frm.docname).reqd

I have made a helper function, for future releases.

4 Likes

Thank You @rmehta

frappe.meta.get_docfield(this.doctype, fieldname, this.frm.docname).read_only=0

Using this method I am able to set the read_only property of a field on form. But in case of Child Table field or fields within the child table it sets the read only property but the field is read-only even after using the cur_frm.refresh_fields()

Can you specify the exact use case?

@rmehta @makarand_b @BhupeshGupta
how can i change the property for a single row in child table based on some condition in the same child row?

There is no easy way that i know, except if the field is inside the child table and the property you want to change is “hidden”, in which case you can use the “depends on” field.

Maybe you can try playing around with jquery and changing some css of the particular field that you need.

@Nahuel_NsoThank you

1 Like

Hi use below jquery script.

var data = frm.doc.accounts;
data.forEach(function(e){
if (e.company != ‘abc’){
$(“[data-idx=’”+e.idx+“’]”).hide()
}
})

Try this solution: