How to listen to row remove event on Child Table?

Hello,

I have two DocTypes.
First one - Test Doctype:

Second - Test Child (which is used as a Table within Test Doctype):

What I want to achieve is that when I remove a row from a Test Child table within Test Doctype Document - a message would be logged out in the console stating “Row from the table was removed” as illustrated here:

I’ve attempted this by creating a Client Script For a DocType Test Doctype and its contents are:

frappe.ui.form.on('Test Doctype', {
	refresh: function(frm) {
		console.log("This fires from refresh action on Test Doctype full function.");  // Fires upon page refresh or document save
	},
	test_table_add: function(frm) {
        console.log("This fires from test_table_add action on Test Doctype full function."); // Never fires
    },
    test_table_remove: function(frm) {
        console.log("This fires from test_table_remove action on Test Doctype full function."); // Never fires
    },
    test_table: function(frm) {
        console.log("This fires from test_table action on Test Doctype full function."); // Never fires
    },
})

frappe.ui.form.on('Test Doctype', {
	refresh(frm) {
		console.log("This fires from refresh action on Test Doctype part function."); // Fires upon page refresh or document save
	},
	test_table_add(frm) {
        console.log("This fires from test_table_add action on Test Doctype part function."); // Never fires
    },
    test_table_remove(frm) {
        console.log("This fires from test_table_remove action on Test Doctype part function."); // Never fires
    },
    test_table(frm) {
        console.log("This fires from test_table action on Test Doctype part function."); // Never fires
    },
})

frappe.ui.form.on('Test Child', { 
    title: function(frm, cdt, cdn) {
        console.log("This fires from title action on Test Child."); // Fires upon editting the "Title" field of any row of the "Test Child" table.
    },
    title_add: function(frm, cdt, cdn) {
        console.log("This fires from title_add action on Test Child."); // Never fires
    },
    title_remove: function(frm, cdt, cdn) {
        console.log("This fires from title_remove action on Test Child."); // Never fires
    },
    remove: function(frm, cdt, cdn) {
        console.log("This fires from remove action on Test Child."); // Never fires
    },
    refresh: function(frm, cdt, cdn) {
        console.log("This fires from remove action on Test Child."); // Never fires
    }
});

As you can see in the code above I’m attempting various ways according to this article: Form Scripts

However, “remove” event never triggers (neither does “add” and some other events that I’ve commented in the code above). I’m unable to figure out how to catch the event when user removes a row in the Child Table via Client Script.

I’m using versions:
ERPNext: v15.61.1
Frappe Framework: v15.68.1

Am I doing something incorrectly or is there a bug with the system / incorrect explanation in the documentation?

Thank you.

Hello :wave:,

Try like this. I think you are writing that in the Doctype script, object. Write in the child table like given below

frappe.ui.form.on(“Child Table Name”, {
table_name_remove : function (frm){ write your logic here on remove},
table_name_add : function(frm) { write your logic here on the new row added}

})

Note: replace table_name with the real table field name.

Regards,
Raj :v:

1 Like

Indeed changing the Client Script to:

frappe.ui.form.on('Test Child', { 
    test_table_add: function(frm) {
        console.log("This logs when row is created.");
    },
    test_table_remove: function(frm) {
        console.log("This logs when row is removed.");
    },
});

did the trick. Thanks, @raj_007. :v:

1 Like