2

I have a doubt about jQuery autocomplete. When I write something in the field like "LI" I need autocomplete returns all the words that starts with "LI" (the words that is in lowercase and uppercase). But when I write this, autocomplete just returns me the words that are in uppercase. Is it possible to change this?

UPDATE: I found a way, I don't know if this is the right way but... I'm using it. It just put in "SELECT" of autocomplete "ILIKE", instead of "LIKE". It works for me, but (again) I don't know if it's the right way to do it!

ChrisF
  • 134,786
  • 31
  • 255
  • 325
mailazs
  • 341
  • 6
  • 22
  • Do you have a local or remote data source? – Andrew Whitaker Mar 13 '13 at 15:17
  • @mzs_newbie: I personally use [COLLATE](http://msdn.microsoft.com/en-us/library/ms184391.aspx) inside of `WHERE` or `ORDER BY` to force case sensitive column/table be interpreted as case insensitive. – Oleg Mar 14 '13 at 12:25
  • 1
    @mzs_newbie: See [the answer](http://stackoverflow.com/a/14610656/315935) for code example. Which database you use? Supports it `COLLATE` inside of SELECTs? Alternatively you can add `LOWER` or `UPPER` functions on both sides of compare operation. – Oleg Mar 14 '13 at 12:31
  • I'm using postgres. Thanks again, I think is better to do what you said! :) – mailazs Mar 14 '13 at 15:05

3 Answers3

1

What about the simplest solution? My solution is in PHP+MySQL, but you can simply adapt it to every scenario you want.

$upperString = strtoupper($stringToCompare);
$query .= "SELECT blablabla WHERE UPPER(columnName) LIKE '%$upperString%'";

Works like a charm

Linuxatico

linuxatico
  • 1,878
  • 30
  • 43
0

Depending on how you build your list for your Autocomplete, this may be automatically built in, for example case does not matter for me in my C# code with Entity frameworks going against a MySQL db.

//Builds a search list for Card Name Search boxes
public JsonResult GetACResults(string term) 
{
    return Json((from item in db.tableName
        where item.NameOfInterest.Contains(term)
        select new
        {
            value = item.NameOfInterest
        }).Distinct().OrderBy(x => x.value).ToList(),
        JsonRequestBehavior.AllowGet);
} //public JsonResult GetACResults(string term)

If this is somthign you have to handle yourself you can look at this post as a solution: Case insensitive 'Contains(string)'

Community
  • 1
  • 1
Mark
  • 3,123
  • 4
  • 20
  • 31
  • Hummm ok. It's that I'm using php and I don't know how to this in php. But thanks for that @Mark :) – mailazs Mar 13 '13 at 17:01
  • The concept should be the same, basically `Contains` is the C# equivalent to `LIKE` in MySQL. I doubt you will have much trouble finding example(s) of searching for db results that using the `LIKE` with PHP. Please mark correct if this solved your problem. – Mark Mar 13 '13 at 17:07
-1

I found a way, I don't know if this is the right way but... I'm using it. It just put in "SELECT" of autocomplete "ILIKE", instead of "LIKE". It works for me, but (again) I don't know if it's the right way to do it!

:)

mailazs
  • 341
  • 6
  • 22
  • What are you using as the source of your autocomplete? Am I missing something but jqGrid doesn't do autocomplete but you are calling the jQuery autocomplete? – Mark Mar 13 '13 at 14:40
  • I'm sorry @Mark... maybe I'm just confused about this... I think is jQuery autocomplete... I will change the title of the question. Thanks for your comment! – mailazs Mar 13 '13 at 15:00