Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7748] Android: Cancel button in search bar does not work

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2013-06-30T00:05:16.000+0000
Affected Version/sRelease 1.7.5, Release 1.8.0.1
Fix Version/s2013 Sprint 14, 2013 Sprint 14 API, Release 3.2.0
ComponentsAndroid
Labelsmodule_searchbar, qe-testadded
ReporterArthur Evans
AssigneeBiju pm
Created2012-02-21T17:40:53.000+0000
Updated2014-03-13T09:38:29.000+0000

Description

Cancel button on a search bar doesn't appear to do anything: that is, it doesn't clear the search bar text, close the onscreen keyboard, or unfocus the search bar. It also doesn't generate an event, so there appears to be no workaround for it. Calling blur() on the search bar manually *does* close the onscreen keyboard, but the search bar maintains its focused appearance. This also means that there seems to be no way to use the built-in cancel button on the search bar. It doesn't generate a 'blur' event, so there's no way to know when it's been pressed in order to use Eric's workaround. In the following test case, note that: 1) No matter what I do, the 'blur' event is not generated. In particular, clicking on a row in the table view does not cause the search bar to blur. 2) Clicking the "Cancel" button does not clear the search field, blur the search field, or close the onscreen keyboard. 3) The Back button will close the onscreen keyboard, but there doesn't seem to be any way to clear the text in the search bar short of erasing it one character at a time.
Ti.UI.setBackgroundColor('#000');

var win = Ti.UI.createWindow({
  title:'Tableview with Filter',
  backgroundColor:'#fff'
});

function makeRow() {
    // generate random string of digits and capital English letters
    // see http://en.wikipedia.org/wiki/Base_36
    return Ti.UI.createTableViewRow({
        title: Math.random().toString(36).substring(7)
    });
}
var searchbar = Ti.UI.createSearchBar({
    showCancel: true,
    hintText: "This is the hint text",
});
searchbar.addEventListener('blur', function(e) {
	Ti.API.info("Blur event called.");
});
searchbar.addEventListener('focus', function(e) {
	Ti.API.info("Focus event called.");
});
var tbl = Ti.UI.createTableView({

    search: searchbar,
});
var data = [];
for(var i=0; i<100; i++) {
    data.push(makeRow());
}
tbl.data = data;
win.add(tbl);
win.open();
There actually is one case where I can generate the 'blur' event, but only on emulator. This is: - Close the keyboard using the back button. - Scroll down using the scroll wheel on the mouse.

Comments

  1. Shameer Jan 2013-03-06

    The problem reproduces with release 3.0.2 and master release 3.1.0 tested on Titanium Studio, build: 3.0.2.201302191606 Titanium SDK version: 3.1.0 Titanium SDK version: 3.0.2 Device: Samsung galaxy s duos Android version: 4.0.4 Android Emulator: Android SDK version: 2.2 On Android, there are several issues with the current implementation, Check Android Platform Implementation Notes http://docs.appcelerator.com/titanium/2.1/#!/api/Titanium.UI.SearchBar
  2. Biju pm 2013-06-21

    fixed the issue. implement the backspace functionality for cancel button https://github.com/appcelerator/titanium_mobile/pull/4408
  3. Federico Casali 2013-10-23

    Cancel button is working as expected. Verified fixed. TiSDK 3.2.0.v20131022050844 CLI 3.2.0 Titanium Studio 3.2.0.201310181940 Closing.

JSON Source