2
0
forked from Wavyzz/dolibarr

FIX - Removal of accents in searches via comboxbox (#34933)

* accents and lower case on combobox

* Fix type

* adding conf

* remove comment

---------

Co-authored-by: ldestailleur <eldy@destailleur.fr>
This commit is contained in:
atm-lucas
2025-08-19 11:50:44 +02:00
committed by GitHub
parent 481e3108a1
commit cfd64ff70a

View File

@@ -498,11 +498,32 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete =
$moreselect2theme = preg_replace('/widthcentpercentminus[^\s]*/', '', $moreselect2theme);
$tmpplugin = 'select2';
$msg = "\n".'<!-- JS CODE TO ENABLE '.$tmpplugin.' for id = '.$htmlname.' -->
<script>
$(document).ready(function () {
$(\''.(dol_escape_js(preg_match('/^\./', $htmlname) ? $htmlname : '#'.$htmlname)).'\').'.$tmpplugin.'({
dir: \'ltr\',';
$msg = "\n".'<!-- JS CODE TO ENABLE '.$tmpplugin.' for id = '.$htmlname.' -->'."\n";
$msg .= "<script>\n";
if (getDolGlobalString('MAIN_DISABLE_ACCENT_INSENSITIVE_SEARCH')) {
$msg .= '
// lowercase + remove accents
function normalizeString(str) {
return str
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "")
.toLowerCase();
}
';
} else {
$msg .= '
// lowercase only (accents kept)
function normalizeString(str) {
return str.toLowerCase();
}
';
}
$msg .= '
$(document).ready(function () {
$(\''.(dol_escape_js(preg_match('/^\./', $htmlname) ? $htmlname : '#'.$htmlname)).'\').'.$tmpplugin.'({
dir: \'ltr\',';
if (preg_match('/onrightofpage/', $morecss)) { // when $morecss contains 'onrightofpage', the select2 component must also be inside a parent with class="parentonrightofpage"
$msg .= ' dropdownAutoWidth: true, dropdownParent: $(\'#'.$htmlname.'\').parent(), '."\n";
}
@@ -513,9 +534,11 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete =
if ($.trim(params.term) === "") {
return data;
}
keywords = (params.term).split(" ");
var term = normalizeString(params.term);
var text = normalizeString(data.text || "");
var keywords = term.split(" ");
for (var i = 0; i < keywords.length; i++) {
if (((data.text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) {
if (text.indexOf(keywords[i]) === -1) {
return null;
}
}