Jquery Autocomplete case sensitive for utf-8 characters

后端 未结 2 747
日久生厌
日久生厌 2021-01-21 05:58

I am using jquery autocomplete plugin to search in a long list of names. It works fine for all latin and english characters, but with turkish characters I have problems, as the

2条回答
  •  深忆病人
    2021-01-21 06:27

    I would recommend taking a look at the accent map demo on the jQueryUI examples page. The idea in the demo is to map accent characters to non-accented characters using a hash. I would change your code to look like that demo:

    $("#PROVINCE_AC_LEFT_autocomplete_label").autocomplete({
        source: function(request, response) {
            var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
            response($.grep(tags_PROVINCE_AC_LEFT, function(value) {
                value = value.label || value.value || value;
                return matcher.test(value) || matcher.test(normalize(value));
            }));
        },
        select: function(event, ui) {
            var selectedObj = ui.item;
            $("#PROVINCE_AC_LEFT_autocomplete_label").val(selectedObj.label);
            $("#PROVINCE_AC_LEFT").val(selectedObj.value);
            return false;
        },
        focus: function(event, ui) {
            $(this).val(ui.item.label);
            return false;
        }
    });
    

    Example: http://jsfiddle.net/gZ8xz/

    (I've only added a few character mappings in the demo)

提交回复
热议问题