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-) - 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) - 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-) - 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 - 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 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) - 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 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 - 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 - 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 ### Shopping list
@ -52,6 +53,7 @@
### General ### 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. `<<`) - Fixed that it wasn't possible to log in using passwords containing special escape sequences (e.g. `<<`)
### API ### API

View File

@ -20,7 +20,6 @@
"datatables.net-bs4": "^1.10.22", "datatables.net-bs4": "^1.10.22",
"datatables.net-colreorder": "^1.5.2", "datatables.net-colreorder": "^1.5.2",
"datatables.net-colreorder-bs4": "^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": "<1.6.0",
"datatables.net-rowgroup-bs4": "^1.1.2", "datatables.net-rowgroup-bs4": "^1.1.2",
"datatables.net-select": "^1.3.1", "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]);; 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) GetUriParam = function (key)
{ {
var currentUri = window.location.search.substring(1); var currentUri = window.location.search.substring(1);

View File

@ -850,6 +850,16 @@ $('[data-toggle="tooltip"]').tooltip();
// serializeJSON defaults // serializeJSON defaults
$.serializeJSON.defaultOptions.checkboxUncheckedValue = "0"; $.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) $(Grocy.UserPermissions).each(function (index, item)
{ {
if (item.has_permission == 0) if (item.has_permission == 0)

View File

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

View File

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

View File

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

View File

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

View File

@ -88,11 +88,7 @@ Grocy.Components.ProductPicker.Enable = function()
$("#camerabarcodescanner-start-button").removeClass("disabled"); $("#camerabarcodescanner-start-button").removeClass("disabled");
} }
$('.product-combobox').combobox({ $(".product-combobox").combobox(Object.assign(BootstrapComboboxDefaults, { "clearIfNoMatch": false }));
appendId: '_text_input',
bsVersion: '4',
clearIfNoMatch: false
});
var prefillProduct = GetUriParam('product-name'); var prefillProduct = GetUriParam('product-name');
var prefillProduct2 = Grocy.Components.ProductPicker.GetPicker().parent().data('prefill-by-name').toString(); 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); Grocy.Components.RecipePicker.SetId(null);
} }
$('.recipe-combobox').combobox({ $(".recipe-combobox").combobox(Object.assign(BootstrapComboboxDefaults, { "clearIfNoMatch": false }));
appendId: '_text_input',
bsVersion: '4',
clearIfNoMatch: false
});
var prefillByName = Grocy.Components.RecipePicker.GetPicker().parent().data('prefill-by-name').toString(); var prefillByName = Grocy.Components.RecipePicker.GetPicker().parent().data('prefill-by-name').toString();
if (typeof prefillByName !== "undefined") if (typeof prefillByName !== "undefined")

View File

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

View File

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

View File

@ -5,9 +5,11 @@
<script src="{{ $U('/viewjs/components/productpicker.js', true) }}?v={{ $version }}"></script> <script src="{{ $U('/viewjs/components/productpicker.js', true) }}?v={{ $version }}"></script>
@endpush @endpush
@push('componentScripts') @push('componentScripts')
@if(isset($ExternalBarcodeLookupPluginName))
<script> <script>
Grocy.ExternalBarcodeLookupPluginName = "{{ $ExternalBarcodeLookupPluginName }}"; Grocy.ExternalBarcodeLookupPluginName = "{{ $ExternalBarcodeLookupPluginName }}";
</script> </script>
@endif
@endpush @endpush
@endonce @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-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/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-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/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-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> <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( @include('components.productpicker', array(
'products' => $products, 'products' => $products,
'nextInputSelector' => '#amount' 'nextInputSelector' => '#amount',
'disallowAddProductWorkflows' => true
)) ))
@include('components.productamountpicker', array( @include('components.productamountpicker', array(

View File

@ -21,18 +21,6 @@
resolved "https://registry.yarnpkg.com/@scarf/scarf/-/scarf-1.4.0.tgz#3bbb984085dbd6d982494538b523be1ce6562972" resolved "https://registry.yarnpkg.com/@scarf/scarf/-/scarf-1.4.0.tgz#3bbb984085dbd6d982494538b523be1ce6562972"
integrity sha512-xxeapPiUXdZAE3che6f3xogoJPeZgig6omHEy1rIY5WVsB3H2BHNnZH+gHG6x91SCWyQCzWGsuL2Hh3ClO5/qQ== 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": "@zxing/library@^0.21.3":
version "0.21.3" version "0.21.3"
resolved "https://registry.yarnpkg.com/@zxing/library/-/library-0.21.3.tgz#0a4cb777701884131832b05922d7e88ef1b87ab4" 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" datatables.net "^1.13.0"
jquery ">=1.7" 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: datatables.net-rowgroup-bs4@^1.1.2:
version "1.6.0" version "1.6.0"
resolved "https://registry.yarnpkg.com/datatables.net-rowgroup-bs4/-/datatables.net-rowgroup-bs4-1.6.0.tgz#452cd6ebb576c76d0341cf4fece21cdbd194a617" 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" datatables.net "^1.13.0"
jquery ">=1.7" 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" version "1.13.11"
resolved "https://registry.yarnpkg.com/datatables.net/-/datatables.net-1.13.11.tgz#e2a4c8b50553512f241ebfcbc078d74d551183b2" resolved "https://registry.yarnpkg.com/datatables.net/-/datatables.net-1.13.11.tgz#e2a4c8b50553512f241ebfcbc078d74d551183b2"
integrity sha512-AE6RkMXziRaqzPcu/pl3SJXeRa6fmXQG/fVjuRESujvkzqDCYEeKTTpPMuVJSGYJpPi32WGSphVNNY1G4nSN/g== integrity sha512-AE6RkMXziRaqzPcu/pl3SJXeRa6fmXQG/fVjuRESujvkzqDCYEeKTTpPMuVJSGYJpPi32WGSphVNNY1G4nSN/g==