Enable last check box only


is there is any way to enable last check box always automatically on save

Hi @GhadaEbrahim,

Please apply custom/client script.

frappe.ui.form.on('DocType Name', {
    before_save: function(frm) {
        
        // Please set your table field name in items
        var table_field = frm.fields_dict['items'];
        var table_rows = table_field.grid.get_data();
        var last_row = table_rows[table_rows.length - 1];

        // Set your checkbox field name
        last_row.your_checkbox_fieldname = 1;
        table_field.refresh();
    }
});

Then reload (Ctrl + Shift + R) and check it.

Thank You!

You can also pass an if statement to the above code just to make sure atleast one item exists in the table.

its working correctly but at second time when I add a new row and click on save it will not remove the previous check

Loop through the rows and set checkbox to 0 and then enable the checkbox for last row

More explanation please

for (var i=0; i<table_rows.length; i++) {
            table_rows[i].your_checkbox_fieldname = 0;
        }
last_row.your_checkbox_fieldname = 1;
        table_field.refresh();