From ec56284a26d73ca72de657f7a8880c99d46dd880 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 19 Mar 2024 16:00:04 +0100 Subject: [PATCH] Bug 20388: Alert if the search field already exists Sponsored-by: The Research University in the Helmholtz Association (KIT) Signed-off-by: Michaela Sieber Signed-off-by: David Schmidt Signed-off-by: Thomas Klausner Signed-off-by: David Schmidt Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer --- .../intranet-tmpl/prog/js/elasticsearch-mappings.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/elasticsearch-mappings.js b/koha-tmpl/intranet-tmpl/prog/js/elasticsearch-mappings.js index 1b3d93fd52..42bd6a5ed4 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/elasticsearch-mappings.js +++ b/koha-tmpl/intranet-tmpl/prog/js/elasticsearch-mappings.js @@ -124,13 +124,18 @@ $(document).ready(function () { $('.add-search-field').click(function() { var table = $(this).closest('table'); let table_id = table.attr('id'); + let dt = $('#' + table_id).DataTable(); var line = $(this).closest('tr'); var search_field_name = $(line).find('input[data-id="search_field_name"]').val(); + let already_exists = dt.data().filter((row, idx) => row[0]['@data-order'] === search_field_name); + if ( already_exists.length ) { + alert(__("SearchField '%s' already exist".format(search_field_name))); + return; + } if (search_field_name.length > 0) { var new_line = clone_line(line); new_line.find('td:first').attr({'data-order': search_field_name}); new_line.appendTo($('table#' + table_id + '>tbody')); - let dt = $('#' + table_id).DataTable(); dt.row.add(new_line).draw(); $(table).on( 'click', '.delete', function () { @@ -140,8 +145,6 @@ $(document).ready(function () { } ); clean_line(line); - } else { - alert("SearchField "+ name + " already exist"); } }); }); -- 2.39.5