Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do UTF-8 characters not work in jquery textcomplete?

I am using the autocompleter jquery-textcomplete in my web app. It's working fine for English and Russian letters. But it is not working for certain special letters such as "ҷ".

Code:

$('.form-control').textcomplete([{
  words: ['тоҷик', 'ҷаҳон', 'english'],
  match: /(^|[^\wа-яёҷ])([\wа-яё]{2,})$/i,
  search: function(term, callback) {
    callback($.map(this.words, function(word) {
      return word.indexOf(term) === 0 ? word : null;
    }));
  },
  index: 2,
  replace: function(word) {
    return '$1' + word + ' ';
  }
}]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.textcomplete/1.8.4/jquery.textcomplete.min.js"></script>

<textarea class="form-control"></textarea>

Here the words 'тоҷик' and 'english' are working but 'ҷаҳон' is not. How can I fix this?

I need the following letters to work: ғ,ӯ,қ,ҳ,ҷ,ӣ and а-я.

like image 797
John Avatar asked Oct 29 '22 21:10

John


1 Answers

Similar question was already answered.

$('#textcomplete').textcomplete([{
  words: ['тоҷик', 'ҷаҳон', 'english'],
  match: /(^|\S*)([^\u0000-\u007f]{2,}|\w{2,})$/,
  search: function(term, callback) {
    callback($.map(this.words, function(word) {
      return word.indexOf(term) === 0 ? word : null;
    }));
  },
  index: 2,
  replace: function(word) {
    return word + ' ';
  }
}]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.textcomplete/1.8.4/jquery.textcomplete.min.js"></script>

<textarea id="textcomplete"></textarea>
like image 153
bigless Avatar answered Nov 15 '22 06:11

bigless