Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1636] Two switches cause repeated event firing

GitHub Issuen/a
Resolution Date2011-04-15T02:58:00.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.5.0
Labelsdefect, ios, iphone, switch
AssigneeBlain Hamon


A customer reported that they were trying to have 2 switches be linked to each other so that when one value changed the other switch changed. The below code, when run, causes many many events to fire when the window is opened. This was run on the iphone, sdk 4.0.2 & 1.4.1

var win = Titanium.UI.currentWindow;

var sw1= Titanium.UI.createSwitch({ value:false, left:215,top:100});

var sw2= Titanium.UI.createSwitch({ value:true, left:215,top:200});


sw2.value = !sw2.value;



sw1.value = !sw1.value;



  1. Stephen Tramer 2011-04-15

    The problem is that this causes an infinite loop, REGARDLESS of when the event is triggered. Switch value 'change' events are fired whenever the value is set, and this includes creating a switch with a 'value' property.

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

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

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

  2. ctredway 2011-04-15

    This happens when just loading the window, without touching a switch. So you are saying that just by having 2 switches with listeners to each other, and not touching either one, this will happen?

  3. Stephen Tramer 2011-04-15

    I am saying two things.

    • Setting 'value' on a control at any time causes the change event to be fired. There are certain circumstances where this might actually be a bug.
    • The customer's logic is wrong to begin with, and even if the event was not fired at window load, flipping a switch would produce exactly the same result.
  4. ctredway 2011-04-15

    I can see how the listeners would cause an infinite loop, but when a control is created and a value is set, IMO, should not fire the change event. This is backwards from what most expect.

  5. Lee Morris 2017-03-02

    Closing as invalid.

JSON Source