1. I'm trying to use jquery-textcomplete with a Unicode string array. When I type an English word, it works properly, but no Unicode words are suggested. I think the problem is with the 'term'. Check the below code and please help me:
var words = ['සහන', 'වනක', 'google', 'suresh namal', 'facebook', 'github', 'microsoft', 'yahoo', 'stackoverflow'];
$('textarea').textcomplete([{
match: /(^|\s)(\w{2,})$/,
search: function (term, callback) {
callback($.map(words, function (word) {
return word.indexOf(term) === 0 ? word : null;
}));
},
replace: function (word) {
return word + ' ';
}
}]);
2. Also, there is a problem with the return key. When I type 'google' after 'stackoverflow' it appears like 'stackoverflowgoogle'. There is no space between 'stackoverflow' and 'google'. How can I solve that? Thanks.
The problem is with your
match
option, where only the latin words are matched (\w
)Reference
You should also include unicode characters in your RegExp, like:
\u0000-\u007f
this is because of using
\s
(notice small "s") in your RegExp, which also replaces a 'space' preceding the keyword:Reference
You could use there
\S
(capital "S") which matches a single character other than space, along with a*
(asterisk) which matches the preceding space 0 or more times.It's probably not a prettiest RegExp, but should do the job for you:
JSFiddle