{ "id": "110119", "key": "ALOY-604", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "11113", "key": "ALOY", "name": "Alloy", "projectCategory": { "id": "10400", "description": "Tools for developing applications", "name": "Tooling" } }, "fixVersions": [ { "id": "15402", "description": "Alloy 1.2.0, concurrent with SDK 3.1.0", "name": "Alloy 1.2.0", "archived": false, "released": true, "releaseDate": "2013-08-15" }, { "id": "15529", "description": "2013 Sprint 13", "name": "2013 Sprint 13", "archived": true, "released": true, "releaseDate": "2013-07-01" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2013-06-20T19:36:34.000+0000", "created": "2013-02-25T16:57:23.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "qe-testadded" ], "versions": [], "issuelinks": [], "assignee": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2013-07-17T22:52:53.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": "13605", "name": "Models" }, { "id": "12326", "name": "XML", "description": "View XML and parsing" } ], "description": "h2.The Problem\r\nWhen events, particularly onClick, are included on views that are childen of a model bound view the event doesn't fire and causes an error.\r\nh2.Test Case\r\n{code}\r\n\r\n\t\r\n\t \r\n\t \r\n\t \r\n\t \r\n\t\r\n\r\n{code}\r\nThis compiles with Alloy to:\r\n{code}\r\nfunction Controller() {\r\n function test(e) {}\r\n require(\"alloy/controllers/BaseController\").apply(this, Array.prototype.slice.call(arguments));\r\n $model = arguments[0] ? arguments[0].$model : null;\r\n var $ = this, exports = {}, __defers = {};\r\n $.__views.TableView = Ti.UI.createTableView({\r\n id: \"TableView\"\r\n });\r\n var __alloyId7 = function(e) {\r\n var models = Alloy.Collections.testModel.models, len = models.length, rows = [];\r\n for (var i = 0; i < len; i++) {\r\n var __alloyId1 = models[i];\r\n __alloyId1.__transform = {};\r\n var __alloyId2 = Ti.UI.createTableViewRow({\r\n id: \"__alloyId0\"\r\n });\r\n rows.push(__alloyId2);\r\n var __alloyId4 = Ti.UI.createView({\r\n id: \"__alloyId3\"\r\n });\r\n __alloyId2.add(__alloyId4);\r\n test ? $.__views.__alloyId3.addEventListener(\"click\", test) : __defers[\"$.__views.__alloyId3!click!test\"] = !0;\r\n var __alloyId6 = Ti.UI.createLabel({\r\n text: \"Location\",\r\n id: \"__alloyId5\"\r\n });\r\n __alloyId4.add(__alloyId6);\r\n }\r\n $.__views.TableView.setData(rows);\r\n };\r\n Alloy.Collections.testModel.on(\"fetch destroy change add remove reset\", __alloyId7);\r\n $.addTopLevelView($.__views.TableView);\r\n exports.destroy = function() {\r\n Alloy.Collections.testModel.off(\"fetch destroy change add remove reset\", __alloyId7);\r\n };\r\n _.extend($, $.__views);\r\n __defers[\"$.__views.__alloyId3!click!test\"] && $.__views.__alloyId3.addEventListener(\"click\", test);\r\n _.extend($, exports);\r\n}\r\n\r\nvar Alloy = require(\"alloy\"), Backbone = Alloy.Backbone, _ = Alloy._, $model;\r\n\r\nmodule.exports = Controller;\r\n{code}\r\nThe problem is that the addEventListener has been added to __views.__alloyId3 rather than __alloyId4. When run you get an error due to attempting to add a listener to an undefined object.\r\n\r\nThe problem emanates from default.js. For collection bound items the state is set to local and the children of the bound view iterated over to generate the code. With the state set to local the .parse function creates a new local id for every object created but this local id is not passed back to .generateNode where any event handlers are added. It looks like the parser can change the object symbol by returning an updated args.symbol but .parse in default.js doesn't do this. If .parse is modified by adding\r\n{code}\r\nargs: {symbol: args.symbol}\r\n{code}\r\nto the end of the return array then the compiler does add the event handler to the locally generated view and the application works.\r\n", "attachment": [], "flagged": false, "summary": "Events inside binded views do not work", "creator": { "name": "mike.diplock", "key": "mike.diplock", "displayName": "Mike Diplock", "active": true, "timeZone": "Europe/London" }, "subtasks": [], "reporter": { "name": "penrique", "key": "penrique", "displayName": "Pedro Enrique", "active": false, "timeZone": "America/Los_Angeles" }, "environment": "Titanium: 3.0.2\r\nAlloy: 1.0.0\r\nPlatform: Android 2.1.4\r\nHost Ubuntu", "comment": { "comments": [ { "id": "245937", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "This problem is solved if you move the repeated component, in this case the TableViewRow, into its own controller. I will look into how to fix this for inline components.", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-04-05T12:19:29.000+0000", "updated": "2013-04-05T12:19:29.000+0000" }, { "id": "255623", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "While a solution is worked on for this issue, a simple workaround is to put the repeated view in its own controller. When the repeated view is created this way, the event handlers will be applied appropriately.", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-06-03T21:59:43.000+0000", "updated": "2013-06-03T21:59:43.000+0000" }, { "id": "258790", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "This was actually resolved by a commit earlier in the development of Alloy 1.2.0. \r\n\r\nPR: https://github.com/appcelerator/alloy/pull/160\r\ntest app: https://github.com/appcelerator/alloy/tree/master/test/apps/testing/ALOY-604\r\n\r\nFunctional testing can pass by running the app on all supported platforms and confirming that the \"test\" message is logged to the console whenever a row is clicked.", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-06-20T19:36:34.000+0000", "updated": "2013-06-20T19:36:34.000+0000" }, { "id": "262249", "author": { "name": "fcasali", "key": "fcasali", "displayName": "Federico Casali", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Verified as fixed.\n\nTitanium SDK 3.1.2.v20130710144553\nAppcelerator Studio 3.1.2.201307101037\nAlloy 1.2.0\n\nAndroid 4.2.2 and iOS 5.\n\nClosing.", "updateAuthor": { "name": "fcasali", "key": "fcasali", "displayName": "Federico Casali", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-07-17T22:52:29.000+0000", "updated": "2013-07-17T22:52:29.000+0000" } ], "maxResults": 4, "total": 4, "startAt": 0 } } }