Fix accent insensitive table search (fixes #2904)

Implemented accent insensitive product name search in productpicker (closes #2905)
This commit is contained in:
Bernd Bestel 2026-04-03 21:36:06 +02:00
parent d4bf5d075a
commit 87bd971d89
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
17 changed files with 191 additions and 197 deletions

View File

@ -56,7 +56,7 @@
- Various display/CSS improvements (thanks @Mik-)
- Prerequisites (PHP extensions, critical files/folders) will now be checked and properly reported if there are problems (thanks @Forceu)
- Improved the the overview pages on mobile devices (main column was hidden) (thanks @Mik-)
- The general search field now searches accent insensitive (and table sorting is also accent insensitive)
- The general table search field now searches accent insensitive (and table sorting is also accent insensitive)
- Fixed that all number inputs are always prefilled in the browser locale number format
- Optimized the handling of settings provided by `data/settingoverrides` files (thanks @dacto)
- Optimized the update script (`update.sh`) to create the backup tar archive before writing to it (was a problem on Btrfs file systems) (thanks @shane-kerr)

View File

@ -13,6 +13,7 @@
- Fixed that changing the location on the purchase page re-initialized the due date based on product defaults (if any)
- Fixed that when undoing a product consume or transfer transaction, the store of the corresponding stock entry wasn't restored
- This will only apply to new consume / transfer transactions, not when undoing transactions made before using this release
- The product picker now searches product names accent insensitive
### Shopping list
@ -52,6 +53,7 @@
### General
- Fixed accent insensitive searching using the general table search field was broken
- Fixed that it wasn't possible to log in using passwords containing special escape sequences (e.g. `<<`)
### API

View File

@ -20,7 +20,6 @@
"datatables.net-bs4": "^1.10.22",
"datatables.net-colreorder": "^1.5.2",
"datatables.net-colreorder-bs4": "^1.5.2",
"datatables.net-plugins": "^1.10.20",
"datatables.net-rowgroup": "<1.6.0",
"datatables.net-rowgroup-bs4": "^1.1.2",
"datatables.net-select": "^1.3.1",

View File

@ -21,6 +21,18 @@ String.prototype.escapeHTML = function()
return this.replace(/[&<>"'`=\/]/g, s => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;', '/': '&#x2F;', '`': '&#x60;', '=': '&#x3D;' })[s]);;
};
// E.g. "Crème fraîche" becomes "Creme fraiche"
String.prototype.accentNeutralise = function ()
{
return this.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
};
// E.g. "<div class='c'>test</div>" becomes "test"
String.prototype.stripHtml = function ()
{
return this.replace(/<.*?>/g, '');
};
GetUriParam = function (key)
{
var currentUri = window.location.search.substring(1);

View File

@ -850,6 +850,16 @@ $('[data-toggle="tooltip"]').tooltip();
// serializeJSON defaults
$.serializeJSON.defaultOptions.checkboxUncheckedValue = "0";
// bootstrap-combobox defaults
BootstrapComboboxDefaults = {
appendId: "_text_input",
bsVersion: "4",
"matcher": function (item)
{
return ~item.accentNeutralise().toLowerCase().indexOf(this.query.accentNeutralise().toLowerCase());
}
};
$(Grocy.UserPermissions).each(function (index, item)
{
if (item.has_permission == 0)

View File

@ -99,7 +99,7 @@ $.extend(true, $.fn.dataTable.defaults, {
}
},
'columnDefs': [
{ type: 'chinese-string', targets: '_all' }
{ type: 'string', targets: '_all' }
],
'rowGroup': {
enable: false,
@ -139,6 +139,23 @@ $.fn.dataTable.ext.type.order["custom-sort-pre"] = function(data)
return (Number.parseFloat($(data).get(0).innerText));
};
$.fn.dataTable.ext.type.search.string = function (s)
{
return s.accentNeutralise();
};
$.fn.dataTable.ext.type.search.html = function (s)
{
return s.stripHtml().accentNeutralise();
};
$.fn.dataTable.ext.type.order["string-pre"] = function (s)
{
return s.accentNeutralise();
};
$.fn.dataTable.ext.type.order["html-pre"] = function (s)
{
return s.stripHtml().accentNeutralise();
};
$('.table').on('column-sizing.dt', function (e, settings)
{
var dtScrollWidth = $('.dataTables_scroll').width();

View File

@ -71,11 +71,7 @@ $('#battery_id').on('change', function(e)
}
});
$('.combobox').combobox({
appendId: '_text_input',
bsVersion: '4',
clearIfNoMatch: false
});
$(".combobox").combobox(Object.assign(BootstrapComboboxDefaults, { "clearIfNoMatch": false }));
$('#battery_id').val('');
$('#battery_id_text_input').val('');

View File

@ -105,11 +105,7 @@ $('#chore_id').on('change', function(e)
}
});
$('.combobox').combobox({
appendId: '_text_input',
bsVersion: '4',
clearIfNoMatch: false
});
$(".combobox").combobox(Object.assign(BootstrapComboboxDefaults, { "clearIfNoMatch": false }));
$('#chore_id_text_input').trigger('change');
Grocy.Components.DateTimePicker.GetInputElement().trigger('input');

View File

@ -34,11 +34,7 @@ Grocy.Components.LocationPicker.Clear = function()
Grocy.Components.LocationPicker.SetId(null);
}
$('.location-combobox').combobox({
appendId: '_text_input',
bsVersion: '4',
clearIfNoMatch: true
});
$(".location-combobox").combobox(BootstrapComboboxDefaults);
var prefillByName = Grocy.Components.LocationPicker.GetPicker().parent().data('prefill-by-name').toString();
if (typeof prefillByName !== "undefined")

View File

@ -88,11 +88,7 @@ Grocy.Components.ProductPicker.Enable = function()
$("#camerabarcodescanner-start-button").removeClass("disabled");
}
$('.product-combobox').combobox({
appendId: '_text_input',
bsVersion: '4',
clearIfNoMatch: false
});
$(".product-combobox").combobox(Object.assign(BootstrapComboboxDefaults, { "clearIfNoMatch": false }));
var prefillProduct = GetUriParam('product-name');
var prefillProduct2 = Grocy.Components.ProductPicker.GetPicker().parent().data('prefill-by-name').toString();

View File

@ -34,11 +34,7 @@ Grocy.Components.RecipePicker.Clear = function()
Grocy.Components.RecipePicker.SetId(null);
}
$('.recipe-combobox').combobox({
appendId: '_text_input',
bsVersion: '4',
clearIfNoMatch: false
});
$(".recipe-combobox").combobox(Object.assign(BootstrapComboboxDefaults, { "clearIfNoMatch": false }));
var prefillByName = Grocy.Components.RecipePicker.GetPicker().parent().data('prefill-by-name').toString();
if (typeof prefillByName !== "undefined")

View File

@ -34,11 +34,7 @@ Grocy.Components.ShoppingLocationPicker.Clear = function()
Grocy.Components.ShoppingLocationPicker.SetId(null);
}
$('.shopping-location-combobox').combobox({
appendId: '_text_input',
bsVersion: '4',
clearIfNoMatch: true
});
$(".shopping-location-combobox").combobox(BootstrapComboboxDefaults);
var prefillByName = Grocy.Components.ShoppingLocationPicker.GetPicker().parent().data('prefill-by-name').toString();
if (typeof prefillByName !== "undefined")

View File

@ -34,10 +34,7 @@ Grocy.Components.UserPicker.Clear = function()
Grocy.Components.UserPicker.SetId(null);
}
$('.user-combobox').combobox({
appendId: '_text_input',
bsVersion: '4'
});
$(".user-combobox").combobox(BootstrapComboboxDefaults);
var prefillUser = Grocy.Components.UserPicker.GetPicker().parent().data('prefill-by-username').toString();
if (typeof prefillUser !== "undefined")

View File

@ -5,9 +5,11 @@
<script src="{{ $U('/viewjs/components/productpicker.js', true) }}?v={{ $version }}"></script>
@endpush
@push('componentScripts')
@if(isset($ExternalBarcodeLookupPluginName))
<script>
Grocy.ExternalBarcodeLookupPluginName = "{{ $ExternalBarcodeLookupPluginName }}";
</script>
@endif
@endpush
@endonce

View File

@ -715,8 +715,6 @@
<script src="{{ $U('/packages/datatables.net-bs4/js/dataTables.bootstrap4.min.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/packages/datatables.net-colreorder/js/dataTables.colReorder.min.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/packages/datatables.net-colreorder-bs4/js/colReorder.bootstrap4.min.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/packages/datatables.net-plugins/filtering/type-based/accent-neutralise.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/packages/datatables.net-plugins/sorting/chinese-string.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/packages/datatables.net-rowgroup/js/dataTables.rowGroup.min.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/packages/datatables.net-rowgroup-bs4/js/rowGroup.bootstrap4.min.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/packages/datatables.net-select/js/dataTables.select.min.js?v=', true) }}{{ $version }}"></script>

View File

@ -281,7 +281,8 @@
@include('components.productpicker', array(
'products' => $products,
'nextInputSelector' => '#amount'
'nextInputSelector' => '#amount',
'disallowAddProductWorkflows' => true
))
@include('components.productamountpicker', array(

View File

@ -21,18 +21,6 @@
resolved "https://registry.yarnpkg.com/@scarf/scarf/-/scarf-1.4.0.tgz#3bbb984085dbd6d982494538b523be1ce6562972"
integrity sha512-xxeapPiUXdZAE3che6f3xogoJPeZgig6omHEy1rIY5WVsB3H2BHNnZH+gHG6x91SCWyQCzWGsuL2Hh3ClO5/qQ==
"@types/jquery@^3.5.16":
version "3.5.34"
resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-3.5.34.tgz#c1993eaac0db03cf9db974976dd8f07bbf7c5708"
integrity sha512-3m3939S3erqmTLJANS/uy0B6V7BorKx7RorcGZVjZ62dF5PAGbKEDZK1CuLtKombJkFA2T1jl8LAIIs7IV6gBQ==
dependencies:
"@types/sizzle" "*"
"@types/sizzle@*":
version "2.3.10"
resolved "https://registry.yarnpkg.com/@types/sizzle/-/sizzle-2.3.10.tgz#277a542aff6776d8a9b15f2ac682a663e3e94bbd"
integrity sha512-TC0dmN0K8YcWEAEfiPi5gJP14eJe30TTGjkvek3iM/1NdHHsdCA/Td6GvNndMOo/iSnIsZ4HuuhrYPDAmbxzww==
"@zxing/library@^0.21.3":
version "0.21.3"
resolved "https://registry.yarnpkg.com/@zxing/library/-/library-0.21.3.tgz#0a4cb777701884131832b05922d7e88ef1b87ab4"
@ -165,14 +153,6 @@ datatables.net-colreorder@1.7.2, datatables.net-colreorder@^1.5.2:
datatables.net "^1.13.0"
jquery ">=1.7"
datatables.net-plugins@^1.10.20:
version "1.13.6"
resolved "https://registry.yarnpkg.com/datatables.net-plugins/-/datatables.net-plugins-1.13.6.tgz#7b0af0675083e2c669ccd09ef7c86878d6c9638d"
integrity sha512-CPLH+09OiEAP3PKbZH7u2qcLajgHhy4fBHCdLzjGWJwKbIkhaPu7tby4jZHQXqoolUznbm3TEpJj4eMI1eqcGw==
dependencies:
"@types/jquery" "^3.5.16"
datatables.net "^1.13.2"
datatables.net-rowgroup-bs4@^1.1.2:
version "1.6.0"
resolved "https://registry.yarnpkg.com/datatables.net-rowgroup-bs4/-/datatables.net-rowgroup-bs4-1.6.0.tgz#452cd6ebb576c76d0341cf4fece21cdbd194a617"
@ -215,7 +195,7 @@ datatables.net-select@1.7.1, datatables.net-select@^1.3.1:
datatables.net "^1.13.0"
jquery ">=1.7"
datatables.net@1.13.11, datatables.net@^1.10.22, datatables.net@^1.13.0, datatables.net@^1.13.2:
datatables.net@1.13.11, datatables.net@^1.10.22, datatables.net@^1.13.0:
version "1.13.11"
resolved "https://registry.yarnpkg.com/datatables.net/-/datatables.net-1.13.11.tgz#e2a4c8b50553512f241ebfcbc078d74d551183b2"
integrity sha512-AE6RkMXziRaqzPcu/pl3SJXeRa6fmXQG/fVjuRESujvkzqDCYEeKTTpPMuVJSGYJpPi32WGSphVNNY1G4nSN/g==