Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Possible to set the search value?

I just noticed that when searching a tableView the search is case sensitive. There doesn't appear to be a property to change this behavior, so what I'm trying to do is use a change event for the searchBar to listen to the user typing something, then make sure the first character is changed to upper case like this:

search.addEventListener('change', function(e) {

function initialCap(search) {
    var newSearch = search.substr(0, 1).toUpperCase() + search.substr(1);
    search.value = newSearch;

Search.value never gets updated, so it stays just as the user entered it.

I can't change the case in my data. Any suggestions?

— asked March 13th 2010 by Dan Giulvezan
  • case
  • searchbar
  • value

3 Answers

  • I have the same problem and did post a few post before yours. Javascript is case sensitive so the autosearch of Ti searchbar is casesensitive also. I'm still looking for a solution.

    — answered March 13th 2010 by michel perrin
  • The the search field value that gets updated on the 'change' event is "e" and is only available within the context of the listener.

    So your initialCap function never gets the updated value because you can't send "e" outside of the listener.

    You need to do your initialCap stuff inside the listener like this:

    search.addEventListener('change', function(e) {
       e.value = e.value.substr(0, 1).toUpperCase() + e.value.substr(1);

    Hope that helps.

    — answered August 20th 2010 by Clifton Labrum
  • There are a couple issues at play here. The first is that you are reassigning the variable search in your function, so that when you try to set search.value, you are adding a property value to the argument to your function (which is named the same as your search bar).

    The other problem is that when you update the value of the search bar (which does work from the callback if you change the argument of your function to 'val' or something like that), you get into an infinite loop where your search bar is constantly changing, and the callback keeps getting called. So "change" isn't exactly what you are looking for.

    I think you could get pretty close by just setting autocapitalization:true on your search bar when you create it.

    — answered August 20th 2010 by Kevin Whinnery
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.