Hide/show grid field in child table on save

Spent a couple of days on this with some luck but still nothing.

I added an attach field “receipts” in the “Expense Claim Detail” child table. Since you cannot attach documents until the form is saved I want to hide the field initially. Then show it after the “Expense Claim” form is saved.

Things I can’t figure out:

I can’t get toggle_display to work with a child table from a custom script on the parent.
I can’t seem to refresh a grid field from the parent doc either.

Please help, losing hair. :sweat:

Try this

cur_frm.fields_dict.expenses.grid.set_column_disp(“receipts”, !cur_frm.doc.__islocal);


Thank you @suyash for this script. I partially used it. This is the script I ended up with:

frappe.ui.form.on("Expense Claim", "refresh", function(frm) {
    if (frm.doc.__islocal){
        cur_frm.fields_dict.expenses.grid.toggle_enable("receipt", false);
        cur_frm.fields_dict.expenses.grid.set_column_disp("receipt", false);
frappe.ui.form.on("Expense Claim", "validate", function(frm) {
    cur_frm.fields_dict.expenses.grid.toggle_enable("receipt", true);
    cur_frm.fields_dict.expenses.grid.set_column_disp("receipt", true);
    msgprint("Please add or check receipts.");

It solves the problem but doesn’t behave exactly as expected. If the set_column_disp command is run BEFORE toggle_enable it will remove the column entirely from the grid. If run after, the column stays, but the “Attach” button is removed. This is good because the grid doesn’t seem to refresh, so adding a column back in works but only if the form is reloaded. The button seems to add back in to the column no problem. I’m guessing there might by some way to refresh the grid without reloading, but regardless I have the functionality that I need.

Marking your post as the solution because I couldn’t have found it without your help. Thanks!

Hi @Dbone! Have you tried using the “Depends On” functionality set in the field you wanted to hide? You can put a condition that if it is true, the field will show. This is an example

So in your use case, you can create a custom field checkbox where you tick it when the document is saved. You can then use the condition above. You can also try searching other discussions about the “Depends On” functionality. Hope this helps!