File Restriction in child table

Not able to restrict file uploading

frappe.ui.form.on('Chapters Content', {
    content_type: function (frm, cdt, cdn) {
        // Trigger the same logic as resource, to enforce file type immediately after selecting content type
        frappe.ui.form.events['Chapters Content'].resource(frm, cdt, cdn);
    },

    resource: function (frm, cdt, cdn) {
        const row = locals[cdt][cdn];

        // Get allowed file extensions based on content type
        let allowed_types = [];

        if (row.content_type === 'Video') {
            allowed_types = ['.mp4', '.mov', '.mkv'];
        } else if (row.content_type === 'Document') {
            allowed_types = ['.pdf', '.doc', '.docx', '.xls', '.xlsx'];
        }

        // Access the child table's row and field widget
        const grid_row = frm.fields_dict["chapters_content"].grid.grid_rows_by_docname[cdn];
        const attach_field = grid_row.fields_dict["resource"];

        // Set new upload options
        attach_field.set_upload_options();
        attach_field.upload_options.restrictions.allowed_file_types = allowed_types;

        // Rebind uploader with new restrictions
        attach_field.file_uploader = new frappe.ui.FileUploader(attach_field.upload_options);
    }
});

child table structure

{
 "actions": [],
 "allow_rename": 1,
 "creation": "2025-05-22 17:56:10.105994",
 "doctype": "DocType",
 "editable_grid": 1,
 "engine": "InnoDB",
 "field_order": [
  "content_type",
  "resource"
 ],
 "fields": [
  {
   "fieldname": "content_type",
   "fieldtype": "Select",
   "label": "Content Type",
   "options": "\nVideo\nDocument"
  },
  {
   "fieldname": "resource",
   "fieldtype": "Attach",
   "label": "Resource"
  }
 ],
 "grid_page_length": 50,
 "index_web_pages_for_search": 1,
 "istable": 1,
 "links": [],
 "modified": "2025-05-22 17:57:13.287529",
 "modified_by": "Administrator",
 "module": "Test",
 "name": "Chapters Content",
 "owner": "Administrator",
 "permissions": [],
 "row_format": "Dynamic",
 "sort_field": "modified",
 "sort_order": "DESC",
 "states": []
}