lundi 2 avril 2018

JQuery Autocomplete isn't working with other languages

I have a JQuery Autocomplete on my contenteditable div and it's working with english. But when I'm trying to type with other languages (f.e. Russian) it isn't even triggering source operator.

$this.autocomplete({
        position: { my : "right top", at: "right bottom" },
        source: function(request, response) {
            var str = _leftMatch(request.term.trim(), $("#tags")[0]);
            // console.log(str);
            str = (str != null) ? str[0] : "";
            response($.ui.autocomplete.filter(
                cities, str));
        },
        focus: function() {
            return false;
        },
        select: function(event, ui) {
            // alert("completing "+ui.item.value);
            var m = _leftMatch($(this).clone().children().remove().end().text().trim(), this)[0];
            var beg = $(this).clone().children().remove().end().text().trim().substring(0, this.selectionStart - m.length);

            var children = $(this).children();
            var txt = ui.item.value;
            $(this).html("");
            var mark = $(markTag);
            mark.children('span').text(txt);
            $(this).append(children);
            $(this).append(mark);
            placeCaretAtEnd($(this)[0]);
            return false;
        },
        search:function(event, ui) {
            var m = _leftMatch($(this).clone().children().remove().end().text().trim(), this);
            return (m != null )
        },
        open: function (event, ui) {
            var cordinates = getSelectionCoords();
            var top = cordinates.y +30 + "px";
            $(this).autocomplete("widget").css({
                "width": ("auto"),
                "top": top,
                "left": cordinates.x
            });


        }

    });

And Here is the _leftMatch function

function _leftMatch(string, area) return string.substring(0, area.selectionStart).match(/[\wäöüÄÖÜß]+$/);




Aucun commentaire:

Enregistrer un commentaire