{ "id": "79505", "key": "TIMOB-5066", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "12077", "description": "", "name": "Sprint 2011-37", "archived": true, "released": true, "releaseDate": "2011-09-19" }, { "id": "11331", "description": "", "name": "Release 1.8.0", "archived": true, "released": true, "releaseDate": "2011-10-31" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2011-09-30T16:40:42.000+0000", "created": "2011-08-22T09:48:02.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "module_toolbar", "qe-testadded" ], "versions": [ { "id": "11244", "name": "Release 1.7.0", "archived": true, "released": true, "releaseDate": "2011-06-13" }, { "id": "11367", "description": "", "name": "Release 1.7.1", "archived": true, "released": true, "releaseDate": "2011-06-21" }, { "id": "11570", "description": "", "name": "Release 1.7.2", "archived": true, "released": true, "releaseDate": "2011-07-21" } ], "issuelinks": [], "assignee": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2014-06-19T12:46:39.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "When win is defined outside of the apps namespace, the click event is fired twice TOTAL for the toolbar, so 2 on the same button or one time on two different buttons.\r\n\r\n\r\n{code}\r\nvar win = Ti.UI.createWindow();\r\n \r\nvar app = {}; \r\n\r\napp.createToolbar = function() {\r\n \r\n var b1 = Ti.UI.createButton({\r\n title: \"b1\",\r\n left: 5\r\n });\r\n \r\n var b2 = Ti.UI.createButton({\r\n title: \"b2\",\r\n right: 5\r\n });\r\n \r\n b1.addEventListener('click', function() {\r\n alert(\"button 1 called.\");\r\n });\r\n b2.addEventListener('click', function() {\r\n alert(\"button 2 called\");\r\n });\r\n \r\n var toolbar = Titanium.UI.createToolbar({\r\n items:[b1, b2]\r\n }); \r\n \r\n win.add(toolbar);\r\n}\r\n\r\napp.createToolbar();\r\n \r\nwin.open();\r\n{code}\r\n\r\n", "attachment": [], "flagged": false, "summary": "Toolbar button click events not always firing ", "creator": { "name": "mapperson", "key": "mapperson", "displayName": "Matthew Apperson", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "mapperson", "key": "mapperson", "displayName": "Matthew Apperson", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "Tested as far back as 1.7.0 on iOS using xCode 4.1", "comment": { "comments": [ { "id": "163696", "author": { "name": "adriankb", "key": "adriankb", "displayName": "Adrian Kirk-Burnnand", "active": true, "timeZone": "America/Los_Angeles" }, "body": "iOS SDK 4.3. My sample view (with some code removed). Buttons fire once or twice and then not again, doesn't matter which button you press first and second. Any of them will first at least once.\r\n\r\n{code}\r\n// Self Initialising View\r\nmyView = new (function() {\r\n\t\r\n\t// Private Vars\r\n\t// var none;\r\n\t\r\n\t// Constructor\r\n\tfunction __construct() {\r\n\t\tvar win = Ti.UI.currentWindow;\r\n\t\t\r\n\t\t// Set Passed in Privates\r\n\t\t// None\r\n\t\t\r\n\t\t// Add RightNavButton\r\n\t\trightNavButton = Ti.UI.createButton({\r\n\t\t\ttitle: 'Save'\r\n\t\t});\r\n\t\t\r\n\t\trightNavButton.addEventListener(\"click\", eventRightNavButtonClick);\r\n\t\t\r\n\t\twin.rightNavButton = rightNavButton;\r\n\t\t\r\n\t\t// Create View\t\t\r\n\t\tvar view = Ti.UI.createView({\r\n\t\t\tbackgroundColor: '#FFFFFF'\r\n\t\t});\r\n\t\t\r\n\t\t// Create Labels\r\n\t\tvar labelPostedBy = Titanium.UI.createLabel({\r\n\t\t\ttext: 'Posted by',\r\n\t\t\ttop: 10,\r\n\t\t\tleft: 60,\r\n\t\t\theight: 20,\r\n\t\t\twidth: 240\r\n\t\t});\r\n\t\t\r\n\t\tvar labelPostedOn = Titanium.UI.createLabel({\r\n\t\t\ttext: 'on \"Today\"',\r\n\t\t\ttop: 35,\r\n\t\t\tleft: 60,\r\n\t\t\theight: 20,\r\n\t\t\twidth: 240\r\n\t\t});\r\n\t\t\r\n\t\t// Add Labels\r\n\t\tview.add(labelPostedBy);\r\n\t\tview.add(labelPostedOn);\r\n\t\t\r\n\t\t// Create TextArea\r\n\t\ttextAreaComment = Titanium.UI.createTextArea({\r\n\t\t\tvalue: 'Comment here',\r\n\t\t\theight: 265,\r\n\t\t\ttop: 65,\r\n\t\t\twidth: 270\r\n\t\t});\r\n\t\t\r\n\t\t// Add TextArea\r\n\t\tview.add(textAreaComment);\r\n\t\t\r\n\t\t// Create Toolbar Buttons\r\n\t\tvar buttonApprove = Titanium.UI.createButton({\r\n\t\t\tbackgroundColor: '#FFFFFF',\r\n\t\t\tborderColor: \"#000000\",\r\n\t\t\tborderWidth: 1,\r\n\t\t\theight:33,\r\n\t\t\twidth:40,\r\n\t\t\ttitle: 'Approve'\r\n\t\t});\r\n\t\t\r\n\t\t// Add Event\r\n\t\tbuttonApprove.addEventListener('click', eventButtonApproveClick);\r\n\t\t\r\n\t\tvar buttonReply = Titanium.UI.createButton({\r\n\t\t\tbackgroundColor: '#FFFFFF',\r\n\t\t\tborderColor: \"#000000\",\r\n\t\t\tborderWidth: 1,\r\n\t\t\theight:33,\r\n\t\t\twidth:40,\r\n\t\t\ttitle: 'Reply'\r\n\t\t});\r\n\t\t\r\n\t\t// Add Event\r\n\t\tbuttonReply.addEventListener('click', eventButtonReplyClick);\r\n\t\t\r\n\t\tvar buttonDelete = Titanium.UI.createButton({\r\n\t\t\tbackgroundColor: '#FFFFFF',\r\n\t\t\tborderColor: \"#000000\",\r\n\t\t\tborderWidth: 1,\r\n\t\t\theight:33,\r\n\t\t\twidth:40,\r\n\t\t\ttitle: 'Delete'\r\n\t\t});\r\n\t\t\r\n\t\t// Add Event\r\n\t\tbuttonDelete.addEventListener('click', eventButtonDeleteClick);\r\n\t\t\r\n\t\tvar buttonSpam = Titanium.UI.createButton({\r\n\t\t\tbackgroundColor: '#FFFFFF',\r\n\t\t\tborderColor: \"#000000\",\r\n\t\t\tborderWidth: 1,\r\n\t\t\theight:33,\r\n\t\t\twidth:40,\r\n\t\t\ttitle: 'Spam'\r\n\t\t});\r\n\t\t\r\n\t\t// Add Event\r\n\t\tbuttonSpam.addEventListener('click', eventButtonSpamClick);\r\n\t\t\r\n\t\tvar flexSpace = Titanium.UI.createButton({\r\n\t\t\tsystemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE\r\n\t\t});\r\n\t\t\r\n\t\t// Create Toolbar\r\n\t\tvar toolbar = Titanium.UI.createToolbar({\r\n\t\t\tbottom: 0,\r\n\t\t\theight: 40,\r\n\t\t\tborderTop:true,\r\n\t\t\tborderBottom:true,\r\n\t\t\titems: [buttonApprove, flexSpace, buttonReply, flexSpace, buttonDelete, flexSpace, buttonSpam],\r\n\t\t});\r\n\t\t\r\n\t\t// Add toolbar\r\n\t\tview.add(toolbar);\r\n\t\t\r\n\t\t// Add view to window\r\n\t\twin.add(view);\r\n\t}\r\n\t\r\n\tfunction eventButtonApproveClick(e) {\r\n\t\talert(\"Approve\");\r\n\t}\r\n\t\t\r\n\tfunction eventButtonReplyClick(e) {\r\n\t\talert('Reply');\r\n\t}\r\n\t\r\n\tfunction eventButtonDeleteClick(e) {\r\n\t\talert(\"Delete\");\r\n\t}\r\n\t\r\n\tfunction eventButtonSpamClick(e) {\r\n\t\talert(\"Spam\");\r\n\t}\r\n\t\t\r\n\tfunction eventRightNavButtonClick(e) {\r\n\t\talert(\"Save\");\r\n\t}\r\n\t\t\r\n\t// Call constructor\r\n\t__construct();\r\n})();\r\n{code}", "updateAuthor": { "name": "adriankb", "key": "adriankb", "displayName": "Adrian Kirk-Burnnand", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-08-22T17:48:42.000+0000", "updated": "2011-08-22T17:48:42.000+0000" }, { "id": "165760", "author": { "name": "vishalnnsingh", "key": "vishalnnsingh", "displayName": "Vishal Kr Singh", "active": true, "timeZone": "America/Los_Angeles" }, "body": "I am having the same issue, Have you guys had a time to work on this yet, can I know what exactly is causing this problem.", "updateAuthor": { "name": "vishalnnsingh", "key": "vishalnnsingh", "displayName": "Vishal Kr Singh", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-09-12T22:02:59.000+0000", "updated": "2011-09-12T22:02:59.000+0000" }, { "id": "165783", "author": { "name": "jaraen", "key": "jaraen", "displayName": "Javier Rayon", "active": true, "timeZone": "America/Los_Angeles" }, "body": "The same here, my case is exposed in this Q&A, with a workaround from Goran Skledar\r\n\r\nhttp://developer.appcelerator.com/question/125494/inexplicable-bug-toolbar-button-only-listens-4-clicks", "updateAuthor": { "name": "jaraen", "key": "jaraen", "displayName": "Javier Rayon", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-09-13T07:08:24.000+0000", "updated": "2011-09-13T07:08:24.000+0000" }, { "id": "166590", "author": { "name": "rmarscher", "key": "rmarscher", "displayName": "Rob Marscher", "active": true, "timeZone": "America/Los_Angeles" }, "body": "This bug does not happen when all elements are created in the global scope. For example, create an app with this in app.js and you will find the click event fires every time:\r\n\r\n{code:javascript}\r\nvar button = Titanium.UI.createButton({\r\n\t\ttitle: 'Click Me',\r\n\t\tstyle:Titanium.UI.iPhone.SystemButtonStyle.BORDERED\r\n\t}),\r\n\tflexSpace = Titanium.UI.createButton({\r\n\t\tsystemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE\r\n\t}),\r\n\twindow = Titanium.UI.createWindow({\r\n\t\tbackgroundColor: \"#ffffff\",\r\n\t\ttitle: \"Toolbar Button Test\"\r\n\t}),\r\n\tnav = Titanium.UI.iPhone.createNavigationGroup({\r\n\t\twindow: window\r\n\t}),\r\n\tcontainerWindow = Ti.UI.createWindow();\r\n\ttimesClicked = 0;\r\n\r\nbutton.addEventListener('click', function() {\r\n\ttimesClicked++;\r\n\talert('Clicked right button (n = ' + timesClicked + ')');\r\n});\r\nwindow.setToolbar([flexSpace, button]);\r\n\r\ncontainerWindow.add(nav);\r\ncontainerWindow.open();\r\n{code}\r\n\r\nHowever, if you wrap the same code in a closure, then you encounter this bug.\r\n\r\n{code:javascript}\r\n(function() {\r\n\tvar button = Titanium.UI.createButton({\r\n\t\t\ttitle: 'Click Me',\r\n\t\t\tstyle:Titanium.UI.iPhone.SystemButtonStyle.BORDERED\r\n\t\t}),\r\n\t\tflexSpace = Titanium.UI.createButton({\r\n\t\t\tsystemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE\r\n\t\t}),\r\n\t\twindow = Titanium.UI.createWindow({\r\n\t\t\tbackgroundColor: \"#ffffff\",\r\n\t\t\ttitle: \"Toolbar Button Test\"\r\n\t\t}),\r\n\t\tnav = Titanium.UI.iPhone.createNavigationGroup({\r\n\t\t\twindow: window\r\n\t\t}),\r\n\t\tcontainerWindow = Ti.UI.createWindow();\r\n\t\ttimesClicked = 0;\r\n\t\r\n\tbutton.addEventListener('click', function() {\r\n\t\ttimesClicked++;\r\n\t\talert('Clicked right button (n = ' + timesClicked + ')');\r\n\t});\r\n\twindow.setToolbar([flexSpace, button]);\r\n\t\r\n\tcontainerWindow.add(nav);\r\n\tcontainerWindow.open();\r\n}());\r\n{code}\r\n", "updateAuthor": { "name": "rmarscher", "key": "rmarscher", "displayName": "Rob Marscher", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-09-21T18:45:03.000+0000", "updated": "2011-09-21T18:45:03.000+0000" }, { "id": "175375", "author": { "name": "wluu", "key": "wluu", "displayName": "Wilson Luu", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing bug. Verified fix using Modulization Toolbar test case on:\r\n\r\nOS: Mac OS X Lion\r\nTitanium Studio, build: 1.0.7.201112080131\r\nSDK build: 1.8.0.1.v20111207180431\r\nDevices: iphone 4S Sprint (5.0.1)", "updateAuthor": { "name": "wluu", "key": "wluu", "displayName": "Wilson Luu", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2011-12-08T10:26:49.000+0000", "updated": "2011-12-08T10:26:49.000+0000" }, { "id": "176438", "author": { "name": "pegli", "key": "pegli", "displayName": "Paul Mietz Egli", "active": true, "timeZone": "America/Los_Angeles" }, "body": "I'm still seeing this issue with similar code compiled with a recent SDK build:\r\n\r\nTitanium Studio, build: 1.0.8.201112161851\r\n[INFO] Titanium SDK version: 1.8.0.1 (12/15/11 16:31 c44f563)\r\niOS 5.0.1 SDK simulator and iPhone 4S.", "updateAuthor": { "name": "pegli", "key": "pegli", "displayName": "Paul Mietz Egli", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-12-18T17:45:28.000+0000", "updated": "2011-12-18T17:45:28.000+0000" }, { "id": "176727", "author": { "name": "pegli", "key": "pegli", "displayName": "Paul Mietz Egli", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Here's a simple app.js that reproduces the problem on the latest SDK. The toolbar button created in global scope works consistently; the toolbar button created in a closure stops responding to clicks after four events.\r\n\r\n{code:javascript}\r\n\r\n\r\nvar win = Ti.UI.createWindow({\r\n backgroundColor: 'white',\r\n});\r\n\r\nvar done1 = Ti.UI.createButton({\r\n systemButton: Ti.UI.iPhone.SystemButton.DONE\r\n});\r\ndone1.addEventListener('click', function(e) {\r\n textField1.blur();\r\n});\r\n\r\nvar textField1 = Ti.UI.createTextField({\r\n top: 10,\r\n left: 30,\r\n right: 30,\r\n height: 32,\r\n value: 'button in global scope',\r\n borderStyle: Ti.UI.INPUT_BORDERSTYLE_BEZEL,\r\n keyboardToolbar: [done1],\r\n});\r\n\r\nwin.add(textField1);\r\n\r\n(function() {\r\n var done2 = Ti.UI.createButton({\r\n systemButton: Ti.UI.iPhone.SystemButton.DONE\r\n });\r\n done2.addEventListener('click', function(e) {\r\n textField2.blur();\r\n });\r\n \r\n var textField2 = Ti.UI.createTextField({\r\n top: 60,\r\n left: 30,\r\n right: 30,\r\n height: 32,\r\n value: 'button in closure',\r\n borderStyle: Ti.UI.INPUT_BORDERSTYLE_BEZEL,\r\n keyboardToolbar: [done2],\r\n });\r\n \r\n win.add(textField2);\r\n})();\r\n\r\nwin.open();\r\n{code}", "updateAuthor": { "name": "pegli", "key": "pegli", "displayName": "Paul Mietz Egli", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-12-20T10:28:24.000+0000", "updated": "2011-12-20T10:28:24.000+0000" }, { "id": "176728", "author": { "name": "pegli", "key": "pegli", "displayName": "Paul Mietz Egli", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Workaround is to hang on to a reference to the toolbar button in the text field, like so:\r\n\r\n{code:javascript}\r\n(function() {\r\n var done2 = Ti.UI.createButton({\r\n systemButton: Ti.UI.iPhone.SystemButton.DONE\r\n });\r\n done2.addEventListener('click', function(e) {\r\n textField2.blur();\r\n });\r\n \r\n var textField2 = Ti.UI.createTextField({\r\n top: 60,\r\n left: 30,\r\n right: 30,\r\n height: 32,\r\n value: 'button in closure',\r\n borderStyle: Ti.UI.INPUT_BORDERSTYLE_BEZEL,\r\n keyboardToolbar: [done2],\r\n buttonRef: done2, // <- WORKAROUND: keeps button working after four presses\r\n });\r\n \r\n win.add(textField2);\r\n})();\r\n{code}", "updateAuthor": { "name": "pegli", "key": "pegli", "displayName": "Paul Mietz Egli", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-12-20T10:31:20.000+0000", "updated": "2011-12-20T10:31:20.000+0000" } ], "maxResults": 9, "total": 9, "startAt": 0 } } }