{ "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

\n

var win = Titanium.UI.currentWindow;

\n

var sw1= Titanium.UI.createSwitch({ value:false,\nleft:215,top:100});
\nwin.add(sw1);

\n

var sw2= Titanium.UI.createSwitch({ value:true,\nleft:215,top:200});
\nwin.add(sw2);

\n

sw1.addEventListener('change',function(e){

\n
\nsw2.value = !sw2.value;\n
\n

});

\n

sw2.addEventListener('change',function(e){

\n
\nsw1.value = !sw1.value;\n
\n

});

{html}", "attachment": [], "flagged": false, "summary": "Two switches cause repeated event firing", "creator": { "name": "ctredway1", "key": "ctredway1", "displayName": "ctredway", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "ctredway1", "key": "ctredway1", "displayName": "ctredway", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "126243", "author": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

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.

\n

Every time a switch was flicked for this window, the following\nwould happen, regardless of when:

\n

s1 -> s2 -> s1 -> s2 -> s1 ->...

\n

The customer needs additional logic in their code to ensure that\nno switch is flipped twice by this requirement.

{html}", "updateAuthor": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:58:00.000+0000", "updated": "2011-04-15T02:58:00.000+0000" }, { "id": "126244", "author": { "name": "ctredway1", "key": "ctredway1", "displayName": "ctredway", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

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?

{html}", "updateAuthor": { "name": "ctredway1", "key": "ctredway1", "displayName": "ctredway", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:58:00.000+0000", "updated": "2011-04-15T02:58:00.000+0000" }, { "id": "126245", "author": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

I am saying two things.

\n
{html}", "updateAuthor": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:58:00.000+0000", "updated": "2011-04-15T02:58:00.000+0000" }, { "id": "126246", "author": { "name": "ctredway1", "key": "ctredway1", "displayName": "ctredway", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

I 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.

{html}", "updateAuthor": { "name": "ctredway1", "key": "ctredway1", "displayName": "ctredway", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:58:01.000+0000", "updated": "2011-04-15T02:58:01.000+0000" }, { "id": "408407", "author": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing as invalid.", "updateAuthor": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2017-03-02T19:05:18.000+0000", "updated": "2017-03-02T19:05:18.000+0000" } ], "maxResults": 5, "total": 5, "startAt": 0 } } }