3

hey mates . recently i used jquery auto-complete tag

http://devthought.com/projects/jquery/textboxlist/

everything goes fine except utf-8 tag suggesting , only English tags are suggested

i guess something goes wrong with script lines it works fine with English tags but not with multi byte languages like Persian

Farshad
  • 947
  • 1
  • 12
  • 23

4 Answers4

3

Probably line 212 in the TextboxList.Autocomplete.js is to blame:

regexp = new RegExp('\\b' + escapeRegExp(search), insensitive ? 'i' : '');

That's looking for the given character after a word boundary. But word boundaries are dependent on recognition of word characters, and JavaScript RegExp's list of word characters is just the ASCII alphanumerics plus _. Because RegExp knows nothing about Unicode this won't work where the word begins with a non-ASCII character.

You could try getting rid of the \\b in which case it would match any suggestion with the given string anywhere inside it, not just at the start of words.

bobince
  • 498,320
  • 101
  • 621
  • 807
  • wow , i was going to answer my own question ( just exactly what u said ) and asking how to solve this now , so it will list anything that has that word not the first word , so now how to solve this ? – Farshad Jan 24 '10 at 15:00
  • How about something like `'(^|[ !-/:-@[-XXX{-~])'+escapeRegExp(search)`? Note, replace `XXX` with a backquote, I can't type it in comments! – bobince Jan 24 '10 at 16:38
1

Your HTTP header is wrong. It should be:

header('Content-Type: application/json; charset=UTF-8');

You can also shorten your code and do the sorting with MySQL:

$sql = 'SELECT `tag` FROM `'.$prefix.'_tags` ORDER BY `tag`';
$result = $db->sql_query($sql);
if (!$result) {
    header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');
    echo mysql_error();
    exit;
}

$response = array();
$i = 0;
while ($row = $db->sql_fetchrow($result)) {
    $response[] = array($i++, $row);
}
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($response);
Gumbo
  • 594,236
  • 102
  • 740
  • 814
  • thanks for shortening my code , although ur code doesnt work at all , maybe u didnt know about my sql part . but my problem is not getting persian ( utf-8 ) tags , and only english ones , its so simple how can i did anything wrong ! – Farshad Jan 24 '10 at 13:31
  • @farshad Ghazanfari: Where is your tag filtering anyway? Where do you include the user’s input? – Gumbo Jan 24 '10 at 13:36
  • i wrote a class for it , and add it to my form , i did not add any filter to tags just read them from sql and ... Can we use different method instead of using json ? – Farshad Jan 24 '10 at 14:03
  • @farshad Ghazanfari: I meant your script is just putting all of your tags out as there is no further restriction i.e. no filtering that the tags must begin with a certain sequence (that what the user has already entered). – Gumbo Jan 24 '10 at 14:07
1

Your content-type header is somewhat wrong. First, it should be content-type:something; charset=something, that is, content-type:text/html; charset=utf-8.

But it is actually suggested to use content-type application/json, see here What is the correct JSON content type?

So, you could do it like this

header("Content-Type:application/json; charset=UTF-8");
Community
  • 1
  • 1
naivists
  • 30,500
  • 5
  • 56
  • 80
  • hey thanks , i did used that header but nothing worked , then i changed type , uh im tired i can't find the bug – Farshad Jan 24 '10 at 13:29
1

Probably line 215 in the TextboxList.Autocomplete.js is to blame:

if (regexp.test(values[i][1])) newvals.push(values[i]);

covert it to

if (values[i][1].indexOf(escapeRegExp(search)) != -1) newvals.push(values[i]);

Bobince (first answer) right, the problem is in line 212, but resolved it can be in line 215