Dispatch UIEvent
Hello,
could you please help me understanding why .dispatchEvent() used to call a radioButton 'click' callback works, while it fails when it's applied to a checkbox?
Here's an example:
var win = new Window ("dialog");
win.alignChildren = "left";
var panel = win.add ("panel");
panel.alignChildren = "left";
var rb1 = panel.add ("radiobutton", undefined, "First RB");
var rb2 = panel.add ("radiobutton", undefined, "Second RB");
var rb3 = panel.add ("radiobutton", undefined, "Third RB");
rb1.value = true;
panel.addEventListener ('click', function(event) {
for (var i = 0; i < panel.children.length; i++) {
if (panel.children.value == true) {
alert(panel.children.text);
return;
}
}
});
var cb1 = win.add("checkBox", undefined, 'First CheckBox');
cb1.onClick = function() { alert("Clicked: " + this.value); }
var okButton = win.add ("button", undefined, "OK");
okButton.onClick = function() { panel.dispatchEvent( new UIEvent ('click') ); } // Works as expected
// okButton.onClick = function() { cb1.dispatchEvent( new UIEvent ('click') ); } // Doesn't work at all
win.show();
I can't figure out the why.
Oh, by the way, if you try the above on ESTK (CC) the alert for the radiobuttons is "wrong" - that is, being selected the rb1, if you click on (say) rb3, the alert says "First RB".
Conversely, if you run this on Photoshop (CC), the alert goes "Third RB".
It seems like the 'click' is catched by the panel callback before it gets to the radiobutton (ESTK) or after (PS). Another nice example of consistency 😉
Thanks!
Davide Barranca
