Client Script for Child Table in Web Form

Good Day All

I’m trying to add multiple rows in the Child Table in the Web Form upon loading. The main goal is, once the “Guest” opens the Link of the Web Form to fill the fields, the rows are already added in the Child Table instead of manually adding them.

I reviewed the Documentation page for Customizing Web Forms, but it wasn’t helpful in this case.
https://frappeframework.com/docs/v13/user/en/guides/portal-development/web-forms

The code I tried to emulate for the Web Form:

frappe.ui.form.on('Main Doctype', {
    refresh(frm) {
        if(frm.doc.__islocal){
            var new_row = frm.add_child("table_fieldname");
                new_row.fieldname_in_childtable = "Test 1";
                frm.refresh_field("table_fieldname");
        }
    }
});

Into this:

frappe.web_form.on('Main Doctype', {
    refresh(frm) {
        if(frm.doc.__islocal){
            var new_row = frm.add_child("table_fieldname");
                new_row.fieldname_in_childtable = "Test 1";
                frm.refresh_field("table_fieldname");
        }
    }
});

I have tried so many different variations of the code based on the Documentation page (Customizing Web Forms), but no luck so far…

Can anyone please help me with the coding ?

@Mohd_RTC21 the code works fine for me .
you know you have the change the table_fieldname and fieldnames with your actual fieldnames ? .

1 Like

I put the code in the Web Form page in the Client Script section.
Where did you put your code ?

P.S: the table_fieldname and fieldnames are just examples, and not what actually written in my code.

Hi , Did you get any support further ?

Hi Guys, Check out this article on Frappe WebForms. I believe this article has the solution. Frappe Web Forms - Sansub

1 Like

Since that site is no longer up: Frappe Web Forms - Sansub

1 Like