Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Some problems with some events of some components
#1
Good afternoon, creating a simple Indy application working with Delphi 11.1 and IW15.2.51 I have noticed some problems with the components IWCheckBox, IWDBCheckBox, IWRadioButton and IWRadioGroup

For IWCheckBox and IWDBCheckBox
---------------------------------------

1.- The OnAsyncClick event is executed 2 times when we make a single click in the LABEL element of the component. It behaves normally when we make a single click on the INPUT element of the component.

2.- The OnAsyncEnter event does not work.

3.- The OnAsyncExit event does not work.

4.- The OnChange event behaves as an asynchronous event.

5.- The OnClick event does not change the state of the checkbox when we click on the LABEL element of the component. It behaves normally when we click on the INPUT element of the component.

For IWRadioButton
---------------------------------------------

1.- The OnAsyncChange event only works when the component is initially in UnChecked state and we click on it, it does not work if its state is changed asynchronously from another component, for example from a button, or when clicking on another IWRadioButton.

2.- The OnAsyncEnter event does not work.

3.- The OnAsyncExit event does not work.

4.- The OnClick event only works if we click on the INPUT element of the component. If we click on the LABEL element of the component, it changes its state (as if it were an asynchronous event) but the OnClick event is not executed.

For IWRadioGroup
------------------------------------------

1.-The OnAsyncChange event is only executed if we click on any of the items of the component. If we change the itemIndex from another component asynchronously, for example from a button, the index changes but the OnAsyncChange event is not triggered.

The OnClick event behaves as an asynchronous event if we click on the LABEL element of the component. It behaves normally if we click on the INPUT element of the component.

Please if someone could confirm this for an eventual correction I would be grateful.
Reply
#2
I'll have a look and let you know ASAP
Reply
#3
1- The OnAsyncChange event is working as designed/expected. HTML DOM OnChange event doesn't trigger if the property is changed via code (you can test this with a simple HTML such as:

Code:
<!DOCTYPE html>
<html>
<body>

<input id="myCheckBox" type="CHECKBOX" onchange="myChangeEvent()">

<script>
function myChangeEvent() {
  alert("onchange triggered");
}
</script>

</body>
</html>


If you open the console in Dev tools (F12) and type:

document.getElementById("myCheckBox").checked = true

you will see that the alert() message won't popup (but it will in any other case where the user directly changes the value via keyboard or mouse).

This is one of multiple security layers of the browser. The browser "knows" and treats differently what is done by direct user intervention (e.g. a mouse click) and what is done via code (setting a property of a DOM element). Our implementation follows the same rules.

2- OnClick of the IWRadioButton: In my tests it works correctly. Have in mind that IWRadioButtons only work if there are more than one with the same Group property. If you have only one RadioButton, it won't work as a CheckBox.

3- CheckBox's OnAsyncChange is indeed triggering twice. This is going to be fixed.

4- OnAsyncEnter/OnAsyncExit are not working as you would expect because they are attached to the label part of the control, not the control itself. To be honest, it's not usual to attach any code to these events for CheckBoxes and RadioButtons, but I'll add it to the TODO list as well

BTW, in all metioned controls, use always OnAsyncChange/OnChange events if you are interested in the state of the control. Never use OnAsyncClick/OnClick events, unless you really want to detect a mouse click over the control, not a state change.
Reply
#4
Thank you Alexandre.
I wanted to clarify that it is the OnAsyncClick event of the IWCheckBox that is executed twice.
Regarding problem 1 that I mention for the IWRadioButton: If I place two IWRadioButton (same group) and I click on the IWRadioButton2, the OnAsyncChange event of the IWRadioButton1 doesn't work, the same if I want to click on the IWRadioButton1, the OnAsyncChange event of the IWRadioButton2 doesn't work.
Regarding the problem 4 that I mention for IWRadioButton: The problem occurs when I want to insert code in the OnAsyncChange and OnClick events simultaneously. Thanks for your help
Reply
#5
> The problem occurs when I want to insert code in the OnAsyncChange and OnClick events simultaneously

Can you please elaborate what's your use case here?

As I mentioned in my response this is the rule of thumb regarding CheckBoxes:

- If you want to respond to state change (checked/unchecked), OnChange/OnAsyncChange are the events you must use.

- If you want to respond to mouse clicks over the control (regardless of the state), OnClick/OnAsyncClick are the events you must use

I'm curious to know what's your use case where you need to use both... (and yes, they both work)
Reply
#6
Quote:Regarding problem 1 that I mention for the IWRadioButton: If I place two IWRadioButton (same group) and I click on the IWRadioButton2, the OnAsyncChange event of the IWRadioButton1 doesn't work, the same if I want to click on the IWRadioButton1, the OnAsyncChange event of the IWRadioButton2 doesn't work.

This is correct and expected. It's the similar to the CheckBox issue. That's how browsers behave.

The DOM event only fires for the control that had a direct user action (mouse click or key pressed). Although the other radio button also changed the state (From checked to unchecked) only the unchecked -> checked state change triggers the event.

This shouldn't be an issue if you have a single event handler for all Radio buttons belonging to the same group (the recommended way to deal with this).
Reply
#7
Please update to IW 15.2.52. It contains fixes for the reported issues (OnAsyncClick fires twice, OnAsyncEnter/OnAsyncExit don't trigger)

https://www.atozed.com/2022/04/intraweb-15-2-52/
Reply
#8
Hello,

I would like to add to this thread the problem we have found with some events that overlap, because it's related with the mentioned previous issues.

The problem is when we have the focus on an iwedit with onasyncexit/onasyncchange event and press a button with onasyncclick/onclick event. The onasyncexit/change event will be raised but the onclick event ignored. Consequently the user has to press the button twice to activate onclick button. 
This could often happen on a formular with lots of edits so it would be nice to be repared. 

I added a simple test case where one can try this by pressing the button while the focus is in one of the edit control. 

thank you very much

Blanca 


Attached Files
.zip   EventTestCase.zip (Size: 90.61 KB / Downloads: 1)
Reply
#9
Hi @Blanca80 I'll test your application and let you know.

Cheers
Reply
#10
@Blanca80

I tested your application and I couldn't find anything wrong with it, other than it is using ShowMessage() in OnAsyncExit and OnAsyncChange events.

I don't think the misbehavior here is caused by method/event overlapping. When the OnAsyncExit event triggers because you clicked on the button, all events related to the IWEdit are handled. The browser will send a request, it will receive a response and the response will popup a window (the message box) which is really an anti-pattern, not only in the web but also in Windows development (Microsoft Windows development guidelines, long ago, already recommended to never switch focus to any other popup window when moving from one control to another).

The browser doesn't trigger the button onclick event at all in some (all?) cases here and there is nothing that IW can do. The OnAsyncChange event is exactly the same (onchange is a "specialized" case of onexit)

I took the liberty to change your test case application and use a Memo to log the events instead of popping up and everything works correctly, in the order that it should happen.


.zip   EventTestCase.zip (Size: 51.61 KB / Downloads: 1)

Please have a look and let me know.
Blanca80
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)