Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3223] iOS - showBookmark missing from searchBar

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-04-18T10:56:41.000+0000
Affected Version/sn/a
Fix Version/sRelease 2.1.0
ComponentsiOS
Labelscore, qe-testadded
ReporterPedro Enrique
AssigneeNeeraj Gupta
Created2011-04-15T03:39:50.000+0000
Updated2013-11-06T19:24:12.000+0000

Description

According to Apple's [Documentation](http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UISearchBar_Class/Reference/Reference.html%23//apple_ref/doc/uid/TP40007529) there is a property for the searchbar that adds a Bookmark icon to the right side of it. I modified a little bit the Obj-C code. Specifically, I added the following code to TiUISearchBar.m and now it is working as expected:
-(void)setShowBookmark_:(id)value
{
    UISearchBar *search = [self searchBar];
    [search setShowsBookmarkButton:[TiUtils boolValue:value]];
    [search sizeToFit];
}
To make this work on Titanium's code just added it to the searchbar with showBookmark true:
var search = Ti.UI.createSearchBar({
    hintText: "Type Something",
    top:0,
    height:44,
    showBookmark: true
});
Then for it's listener, I modified the Obj-C code a little more:
// called when bookmark button pressed
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar                   
{   
    //TODO: update to the new event model

    NSString * text = [searchBar text];
    [self.proxy replaceValue:text forKey:@"value" notification:NO];

    if ([self.proxy _hasListeners:@"bookmark"])
    {
        [self.proxy fireEvent:@"bookmark" withObject:[NSDictionary dictionaryWithObject:text forKey:@"value"]];
    }


    if (delegate!=nil && [delegate respondsToSelector:@selector(searchBarBookmarkButtonClicked:)])
    {
        [delegate searchBarBookmarkButtonClicked:searchBar];
    }

}
And the JS is like this:
search.addEventListener('bookmark', function(e){
    alert(e);
});
Tested in Ti SDK 1.6 Release iPhone Simulator 4.2

Comments

  1. Zipcar (Goss) 2011-04-15

    This feature is necessary for our project, if it can be prioritized.

  2. Reggie Seagraves 2011-04-15

    As a low priority item, this will not be looked at until after Sprint 16.

  3. Hidayet Dogan 2012-02-17

    I've pulled request on github for Pedro Enrique's solution with adding documentation. See here: https://github.com/appcelerator/titanium_mobile/pull/1458 Ticket is already tagged for 1.8.0 release but I hope it'll be included in next release.
  4. Hidayet Dogan 2012-04-05

    Tested with: Titanium SDK: 2.0.0 (04/06/12 00:35 8e4d621) iPhone SDK: 5.0 iPhone Simulator Screenshots: [http://oi41.tinypic.com/34skkcy.jpg] [http://oi42.tinypic.com/xeg3ee.jpg] [http://oi41.tinypic.com/2ibnf9s.jpg] [http://oi42.tinypic.com/30nayxs.jpg] Here are the functional test application source code:
       var window = Titanium.UI.createWindow({
       	backgroundColor: "white"
       });
       
       var searchBar = Titanium.UI.createSearchBar({
       	top: 0,
       	height: 44
       });
       
       searchBar.addEventListener('bookmark', function(e) {
       	alert('Bookmark button clicked. Value: ' + e.value);
       });
       
       var buttonFocus = Titanium.UI.createButton({
       	title: 'Focus',
       	top: 75,
       	left: 20,
       	height: 30
       });
       
       buttonFocus.addEventListener('click', function(e) {
       	searchBar.focus();
       });
       
       var buttonBlur = Titanium.UI.createButton({
       	title: 'Blur',
       	top: 75,
       	right: 20,
       	height: 30
       });
       
       buttonBlur.addEventListener('click', function(e) {
       	searchBar.blur();
       });
       
       var buttonBookmark = Titanium.UI.createButton({
       	title: 'Toggle Bookmark',
       	top: 125,
       	height: 30
       });
       
       buttonBookmark.addEventListener('click', function(e) {
       	searchBar.showBookmark = !searchBar.showBookmark;
       });
       
       window.add(searchBar);
       window.add(buttonFocus);
       window.add(buttonBlur);
       window.add(buttonBookmark);
       window.open();
       
  5. Stephen Tramer 2012-04-18

    Here is an additional test which should be run:

    Searchbar w/bookmark in tableview

       var window = Titanium.UI.createWindow({
           backgroundColor: "white"
       });
        
       var searchBar = Titanium.UI.createSearchBar({
       	showBookmark: true
       });
        
       searchBar.addEventListener('bookmark', function(e) {
           alert('Bookmark button clicked. Value: ' + e.value);
       });
        
       var table = Ti.UI.createTableView({
       	data:[{title:"Row 1"}, {title:"Row 2"}, {title:"Row 3"}],
       	search:searchBar
       });
       
       window.add(table);
       window.open();
       
  6. Natalie Huynh 2012-06-06

    Tested with 2.1.0.v20120606112649 iPad 3 5.1.1 and iPhone 3gs 4.3
  7. Shameer Jan 2013-11-06

    Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/4758

JSON Source