[TIMOB-1636] Two switches cause repeated event firing
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Trivial |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2011-04-15T02:58:00.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.5.0 |
Components | iOS |
Labels | defect, ios, iphone, switch |
Reporter | ctredway |
Assignee | Blain Hamon |
Created | 2011-04-15T02:57:59.000+0000 |
Updated | 2017-03-02T19:05:18.000+0000 |
Description
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});
win.add(sw1);
var sw2= Titanium.UI.createSwitch({ value:true,
left:215,top:200});
win.add(sw2);
sw1.addEventListener('change',function(e){
sw2.value = !sw2.value;
});
sw2.addEventListener('change',function(e){
sw1.value = !sw1.value;
});
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.
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?
I am saying two things.
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.
Closing as invalid.