{ "id": "119448", "key": "ALOY-817", "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": "15403", "description": "Alloy 1.3.0", "name": "Alloy 1.3.0", "archived": false, "released": true, "releaseDate": "2013-12-20" }, { "id": "15602", "description": "Alloy 1.2.2", "name": "Alloy 1.2.2", "archived": false, "released": true, "releaseDate": "2013-09-18" }, { "id": "15670", "description": "2013 Sprint 18", "name": "2013 Sprint 18", "archived": true, "released": true, "releaseDate": "2013-09-06" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2013-09-04T20:57:13.000+0000", "created": "2013-09-04T15:53:30.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "qe-testadded" ], "versions": [ { "id": "15570", "description": "Alloy 1.2.1", "name": "Alloy 1.2.1", "archived": false, "released": true, "releaseDate": "2013-08-27" }, { "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" } ], "issuelinks": [], "assignee": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2013-09-05T19:30:25.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": "12326", "name": "XML", "description": "View XML and parsing" } ], "description": "h2. Problem description\r\nWhen adding an onClick event to a Map view (using the Android Map module), instead of using addEventListener, alloy is using on().\r\n\r\nh2. Steps to reproduce\r\n1) Create a new Alloy app\r\n2) Use the following code in index.xml:\r\n\r\n{code:xml}\r\n\r\n \r\n \r\n \r\n\r\n{code}\r\n\r\nAdd a report function in index.js:\r\n\r\n{code:javascript}\r\nfunction report(event) {\r\n alert('Hello');\r\n}\r\n\r\n$.index.open();\r\n{code}\r\n\r\nAssign the value to Alloy.Globals.Map in alloy.js:\r\n\r\n{code:javascript}\r\nAlloy.Globals.Map = Ti.Platform.osname === 'android' ? require('ti.map') : Ti.Map;\r\n{code}\r\n\r\nh2. Results\r\nWhen running the app, the result of the onClick is:\r\n\r\n{code:javascript}\r\n.__views.map2 = Alloy.Globals.Map.createView({\r\n id: \"map2\",\r\n ns: \"Alloy.Globals.Map\"\r\n});\r\n$.__views.index.add($.__views.map2);\r\nreport ? $.__views.map2.on(\"click\", report) : __defers[\"$.__views.map2!click!report\"] = true;\r\n{code}\r\n\r\nUsing the normal Ti.Map, the listener is added using addEventListener.\r\n\r\nh2. workaround\r\n\r\nDon't specify the event listener in the markup, just do it in the controller\r\n\r\n{code:javascript}\r\n$.map2.addEventListener('click', function(e) {});\r\n{code}", "attachment": [], "flagged": false, "summary": "Wrong method used to add an event listener when using custom namespace in markup", "creator": { "name": "dcassenti", "key": "dcassenti", "displayName": "Davide Cassenti", "active": true, "timeZone": "Europe/Berlin" }, "subtasks": [], "reporter": { "name": "dcassenti", "key": "dcassenti", "displayName": "Davide Cassenti", "active": true, "timeZone": "Europe/Berlin" }, "environment": "alloy 1.2.1\r\nSDK 3.1.2\r\n", "comment": { "comments": [ { "id": "269572", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "PR (master): https://github.com/appcelerator/alloy/pull/239\r\ncommit (1_2_X): https://github.com/appcelerator/alloy/commit/05ad3e792d3e5f45a7df592dcbdc82cbd6e07999\r\ntest app: https://github.com/appcelerator/alloy/tree/master/test/apps/testing/ALOY-817\r\n\r\nThis fixed attaching event listeners to developer-defined namespace objects. From now on, only the following markup element types will use {{on()}} for event handling. All other will use {{addEventListener()}}:\r\n\r\n* \r\n* \r\n* \r\n* \r\n\r\nfunctional test:\r\n\r\n# Run test app \r\n# Ensure that the app loads without compile or runtime error\r\n# Check the console output. Ensure that you see all 7 event handlers fire their log messages. The list should contain the following:\r\n{code}\r\n[INFO] collection change\r\n[INFO] model change\r\n[INFO] another model change\r\n[INFO] button clicked\r\n[INFO] map clicked\r\n[INFO] window clicked\r\n[INFO] empty controller init\r\n{code}\r\n# If all 7 event handlers fired, it's not completely necessary, but you can inspect the generated code for the \"index\" and \"empty\" controllers, making sure that {{on}} is used for all models, collection, and controllers while {{addEventListener}} is used for everything else, including the map.", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-09-04T20:57:13.000+0000", "updated": "2013-09-04T20:57:13.000+0000" }, { "id": "269803", "author": { "name": "fcasali", "key": "fcasali", "displayName": "Federico Casali", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Verified as fixed with the provided sample code.\n\nAlso verified checking 'index' and 'empty' controllers, 'on' is used for models, collections and controllers, while addEventListener is used for everything else (window, map , button... )\n\nTitanium SDK .1.3.v20130904134612\nAlloy 1.2.2\nCLI 3.1.2.GA\nNode 0.10.13\n\nClosing.", "updateAuthor": { "name": "fcasali", "key": "fcasali", "displayName": "Federico Casali", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-09-05T19:22:26.000+0000", "updated": "2013-09-05T19:22:26.000+0000" } ], "maxResults": 7, "total": 7, "startAt": 0 } } }