5

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 а-я.

Boann
  • 48,794
  • 16
  • 117
  • 146
John
  • 468
  • 3
  • 16

1 Answers1

2

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>
bigless
  • 2,849
  • 19
  • 31
  • Thanks for answering! I use textcomplete because in the autocomplete after writing the first word the second time the list of words does not appear. Maybe it's possible to solve this problem but I have not tried it yet. @bigless – John Jan 01 '18 at 09:43
  • @John yea I already removed that stupid question and irrelevant code. I got it. textcomplete is for textarea while autocomplete(without tweaking) for inputs. – bigless Jan 01 '18 at 09:47
  • Ok, Thanks! Please comment this code for me if you can: `/(^|\S*)([^\u0000-\u007f]{2,}|\w{2,})$/` @bigless – John Jan 01 '18 at 09:49
  • @John this regex is already described in link I provided at beginning. – bigless Jan 01 '18 at 09:51
  • That's all, I understood your code. Thank you for the answer @bigless – John Jan 01 '18 at 09:57