Search code examples
jqueryautocompletecase-sensitive

Disable case sensitive with autocomplete


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!


Solution

  • 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)'