Disable "Remove" Button to stop deletion of child table records

Dear Team,

Kindly suggest, how to Disable “Remove” Button to stop deletion of child table records.

@KanchanChauhan can you help with the solution?

Did you try setting up the Permissions in Role Permission Manager?

But It dint work for child table

@Ram_Gopal_Rao did you find any solution ?

I hope this will help you.

Try this:
$('*[data-fieldname="items"]').find('.grid-remove-rows').hide();

where ‘items’ is your table name in your doctype.

3 Likes

Worked :slight_smile:

Plus you can hide the trash button which comes in child table’s popup window.

[data-fieldname="items"]_on_form_rendered:function(frm, grid_row, cdt, cdn){
	 $(".grid-delete-row").hide()
}

This code works 100% to hide delete button for both before and after opening row on child table

frappe.ui.form.on('Sales Order', {
    refresh(frm) {
        // your code here
        $('*[data-fieldname="items"]').find('.grid-remove-rows').hide();
    },
});

frappe.ui.form.on('Sales Order Item', {
	refresh(frm) {
		// your code here
		
	},
	
    form_render(frm, cdt, cdn){
        frm.fields_dict.items.grid.wrapper.find('.grid-delete-row').hide();
        frm.fields_dict.items.grid.wrapper.find('.grid-duplicate-row').hide();
        frm.fields_dict.items.grid.wrapper.find('.grid-move-row').hide();
        frm.fields_dict.items.grid.wrapper.find('.grid-append-row').hide();
        frm.fields_dict.items.grid.wrapper.find('.grid-insert-row-below').hide();
        frm.fields_dict.items.grid.wrapper.find('.grid-insert-row').hide();
    },
});
2 Likes

You can use something like:

frm.get_field("TABLE_NAME").grid.df.cannot_delete_rows = true;

right method is

frm.set_df_property(‘table_field_name’, ‘cannot_delete_rows’, 1);

3 Likes

use css to the specific doctype you want to hide both add and delete buttons.
Note: css file name should be same as the others in the your_doctype folder like in .py, .js files.

.grid-buttons {
    display: none;
  }

Tested script WORKED 100%

To hide the add and remove btn

frappe.ui.form.on('Parent Doctype Name ', {
refresh(frm) {

    // your code here
    $('*[data-fieldname="CHILD TABLE NAME IN THE DOCTYPE"]').find('.grid-remove-rows').hide();
    $('*[data-fieldname="CHILD TABLE NAME IN THE DOCTYPE"]').find('.grid-add-row').hide();

    
},

});
To hide all btns inside the child table row

frappe.ui.form.on('CHILD TABLE DOC NAME, {
form_render(frm) {
// your code here

   $('*[data-fieldname="CHILD TABLE NAME INSIDE DOC TYPE"]').find('.grid-delete-row').hide();
   $('*[data-fieldname="CHILD TABLE NAME INSIDE DOC TYPE"]').find('.grid-duplicate-row').hide();
   $('*[data-fieldname="CHILD TABLE NAME INSIDE DOC TYPE"]').find('.grid-move-row').hide();
   $('*[data-fieldname="CHILD TABLE NAME INSIDE DOC TYPE"]').find('.grid-append-row').hide();
   $('*[data-fieldname="CHILD TABLE NAME INSIDE DOC TYPE"]').find('.grid-insert-row-below').hide();
   $('*[data-fieldname="CHILD TABLE NAME INSIDE DOC TYPE"]').find('.grid-insert-row').hide();
   

},

});