0

Hello i'm using Jquery autocomplete for a project but i've a particular problem with my language. Here in albania our alphabet includes characters like ë and ç but some people don't know keyboard combination to produce this character and i'm trying to return these words using 'e' and 'c'. Example when people search for 'Dhermi' i want to show the word 'Dhërmi' as a suggestions. Same for the word "canta" i want to show "çanta". Here are many words like these so i want a function to return data in this way.

Below is my function

$("#search").autocomplete({
    minLength:0,
    delay:10,
    appendTo: ".search",
    source:function(request, response) {

// 
        var matchernormal = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );

        matcher = $.grep(tagsarr, function( item ){return matchernormal.test(item);})

        console.log(matcher)

        // Limit Results
        var results = $.ui.autocomplete.filter(matcher, request.term);

        response(results.slice(0, 10));

    }
});

I'll be grateful if someone could help me with this problem that i've encountered.

Int
  • 23
  • 7

1 Answers1

0

What you are looking for is accent folding: https://jqueryui.com/autocomplete/#folding

you can have a map of the accent characters to the normalised characters

var accentMap = {
  "á": "a",
  "ö": "o"
};

and a function to convert one from other (see the example link)

var normalize = function( term ) {....}

and compare with the normalised value of the string as well as the original one:

return matcher.test( value ) || matcher.test( normalize( value ) );
suvartheec
  • 3,484
  • 1
  • 17
  • 21