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:
@@ -498,11 +498,32 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete =
|
|||||||
$moreselect2theme = preg_replace('/widthcentpercentminus[^\s]*/', '', $moreselect2theme);
|
$moreselect2theme = preg_replace('/widthcentpercentminus[^\s]*/', '', $moreselect2theme);
|
||||||
|
|
||||||
$tmpplugin = 'select2';
|
$tmpplugin = 'select2';
|
||||||
$msg = "\n".'<!-- JS CODE TO ENABLE '.$tmpplugin.' for id = '.$htmlname.' -->
|
$msg = "\n".'<!-- JS CODE TO ENABLE '.$tmpplugin.' for id = '.$htmlname.' -->'."\n";
|
||||||
<script>
|
$msg .= "<script>\n";
|
||||||
$(document).ready(function () {
|
|
||||||
$(\''.(dol_escape_js(preg_match('/^\./', $htmlname) ? $htmlname : '#'.$htmlname)).'\').'.$tmpplugin.'({
|
if (getDolGlobalString('MAIN_DISABLE_ACCENT_INSENSITIVE_SEARCH')) {
|
||||||
dir: \'ltr\',';
|
$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"
|
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";
|
$msg .= ' dropdownAutoWidth: true, dropdownParent: $(\'#'.$htmlname.'\').parent(), '."\n";
|
||||||
}
|
}
|
||||||
@@ -513,9 +534,11 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete =
|
|||||||
if ($.trim(params.term) === "") {
|
if ($.trim(params.term) === "") {
|
||||||
return data;
|
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++) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user