Bug 36640: Fix behaviour of 'Clear filter'

It must be disabled when the main search input is empty.

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Jonathan Druart 2024-11-14 11:16:06 +01:00 committed by Katrin Fischer
parent d9448e1bda
commit 0974d1a916
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
2 changed files with 11 additions and 3 deletions

View File

@ -318,6 +318,13 @@ function KohaTable(id_selector, dt_parameters, table_settings, add_filters, defa
}
});
table_dt.on( 'search.dt', function ( e, settings ) {
// When the DataTables search function is triggered,
// enable or disable the "Clear filter" button based on
// the presence of a search string
toggledClearFilter(table_dt.search(), settings.nTable.id);
});
return table;
}
</script>

View File

@ -75,10 +75,11 @@ var dataTablesDefaults = {
DataTable.defaults.column.orderSequence = ['asc', 'desc'];
function toggledClearFilter(searchText, tableId){
let clear_filter_button = $("#" + tableId + "_wrapper").find(".dt_button_clear_filter");
if( searchText == "" ){
$("#" + tableId + "_wrapper").find(".dt_button_clear_filter").addClass("disabled");
clear_filter_button.addClass("disabled");
} else {
$("#" + tableId + "_wrapper").find(".dt_button_clear_filter").removeClass("disabled");
clear_filter_button.removeClass("disabled");
}
}
@ -1076,7 +1077,7 @@ function _dt_save_restore_state(table_settings, external_filter_nodes={}){
// When the DataTables search function is triggered,
// enable or disable the "Clear filter" button based on
// the presence of a search string
toggledClearFilter(settings.oPreviousSearch.sSearch, settings.nTable.id);
toggledClearFilter(table_dt.search(), settings.nTable.id);
});
return table;