{ "id": "62268", "key": "TIMOB-1636", "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": "11225", "name": "Release 1.5.0", "archived": true, "released": true, "releaseDate": "2010-12-14" } ], "resolution": { "id": "7", "description": "", "name": "Invalid" }, "resolutiondate": "2011-04-15T02:58:00.000+0000", "created": "2011-04-15T02:57:59.000+0000", "priority": { "name": "Trivial", "id": "5" }, "labels": [ "defect", "ios", "iphone", "switch" ], "versions": [], "issuelinks": [], "assignee": { "name": "blainhamon", "key": "blainhamon", "displayName": "Blain Hamon", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2017-03-02T19:05:18.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": "{html}
A customer reported that they were trying to have 2 switches be\nlinked to each other so that when one value changed the other\nswitch changed. The below code, when run, causes many many events\nto fire when the window is opened. This was run on the iphone, sdk\n4.0.2 & 1.4.1
\nvar win = Titanium.UI.currentWindow;
\nvar sw1= Titanium.UI.createSwitch({ value:false,\nleft:215,top:100});
\nwin.add(sw1);
var sw2= Titanium.UI.createSwitch({ value:true,\nleft:215,top:200});
\nwin.add(sw2);
sw1.addEventListener('change',function(e){
\nsw2.value = !sw2.value;
\n
\n});
\nsw2.addEventListener('change',function(e){
\nsw1.value = !sw1.value;
\n
\n});
The problem is that this causes an infinite loop, REGARDLESS of\nwhen the event is triggered. Switch value 'change' events are fired\nwhenever the value is set, and this includes creating a switch with\na 'value' property.
\nEvery time a switch was flicked for this window, the following\nwould happen, regardless of when:
\ns1 -> s2 -> s1 -> s2 -> s1 ->...
\nThe customer needs additional logic in their code to ensure that\nno switch is flipped twice by this requirement.
This happens when just loading the window, without touching a\nswitch. So you are saying that just by having 2 switches with\nlisteners to each other, and not touching either one, this will\nhappen?
I am saying two things.
\nI can see how the listeners would cause an infinite loop, but\nwhen a control is created and a value is set, IMO, should not fire\nthe change event. This is backwards from what most expect.