From 88133a9408be1c6fcfee40e8050bf0a76f5be8b6 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 23 Dec 2022 11:32:12 +0000 Subject: [PATCH] Bug 32520: Iterate search_fields This pretty much matches the iterators in koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc. Now we need to work out the best way to pass the DefaultPatronSearchFields preference into the search_fields variable.. Perhaps pass it as part of the options at function call time? --- .../prog/js/patron-autocomplete.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js b/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js index 5f0aeb55592..43f1970a83a 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js +++ b/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js @@ -13,22 +13,22 @@ function patron_autocomplete(node, options) { on_select_callback = options['on-select-callback']; } } - const search_fields = ['me.surname', 'me.firstname', 'me.cardnumber']; + const search_fields = ['surname', 'firstname', 'cardnumber']; return node.autocomplete({ source: function( request, response ) { let subquery_and = []; request.term.split(' ') .filter(function(s){ return s.length }) .forEach(function(pattern,i){ - subquery_and.push( - [ - {'me.surname': {'like': '%' + pattern + '%'}}, - {'me.firstname': {'like': '%' + pattern + '%'}}, - {'me.cardnumber': {'like': pattern + '%'}}, - ] - ); + let subquery_or = []; + search_fields.forEach(function(field,i){ + subquery_or.push( + {["me."+field]: {'like': '%' + pattern + '%'}} + ); + }); + subquery_and.push(subquery_or); }); - let q = {"-and": subquery_and}; + let q = {"-and": subquery_and }; let params = { '_page': 1, '_per_page': 10, -- 2.39.0