I am using jQuery Autocomplete plugin 1.1 for a project.
Here is my calling code:
$("#txtCombo").autocomplete("http://www.example.com/autocomplete.php", {
autoFill: false,
width: 550,
minChars: 3,
selectFirst: false
});
The problem is that what ever I type in the autocomplete, it gets converted to lower case when it reaches the php file autocomplete.php
For e.g. if I search for "Smart Boy", the php file will receive "smart boy". This is good in a way because when I make a like search in the database for the query, I get all the matching results irrespective of the letter case.
But here is the problem, when I run this script for greek characters, for e.g. when I enter query "Μικρές Οικιακές Συσκευές", it is converted to "μικρές οικιακές συσκευές". Now when I use a like query as below:
"SELECT ID, NAME FROM CATEGORIES WHERE NAME LIKE '%".$query."%'"
I get nothing, because the database does not check for greek letters with case-insensitive search.
I tried using collation keyword like this:
"SELECT ID, NAME FROM CATEGORIES WHERE NAME LIKE '%".$query."%' COLLATE utf8_general_ci"
But I get this error: COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'latin1'
I understand that the charset of the tables is latin1 so it wont work with utf8 collation, so if I try using latin1_general_ci collation, it gives me this error:
Illegal mix of collations (utf8_general_ci,IMPLICIT) and (latin1_general_ci,EXPLICIT) for operation 'like'
Only if I can stop autocomplete by converting the query to lowercase, it would solve the problem pretty much.
Why is the plugin converting to lowercase anyway when I have not specified any such thing in the parameters to call?
Any ideas....
I have finally found a solution by searching the file jquery.autocomplete.js for the word "lower". I found out that it converts search queries to lower-case if an option "matchCase" is not found in the call parameters, or if it is not set to true.
So I edited my calling like this:
$("#txtCombo").autocomplete("http://www.example.com/autocomplete.php", {
autoFill: false,
width: 550,
minChars: 3,
matchCase: true,
selectFirst: false
});
And it worked! Now it does not convert the query to lower-case.
I think posting a question it self clarifies new ways to look for a solution. I did not get the idea to look for the word "lower" in the plugin file itself before that. Even though the plugin file was minified, still I found this code in there:
... if(!options.matchCase)currentValue=currentValue.toLowerCase(); ...
which gave me the idea why it could have been converting to lowercase.
May be this answer will help someone with the same situation.
Regards
You can use the mixed case matching... and on the onClickAfter callback.. you have access to the original item with the case intact.
For example... if my dataset had an attribute called 'name', I can retrieve it's original value with:
onClickAfter: function (node, a, item, event) {
var name = item.name;
. . . . .