Web 2 Xojo 2023r4 - I need to handle Enter/Return in WebSearchField

According to documentation the Enter key and Return key should be handled by Pressed event on the WebSearchField. However, when I open page and the focus is in the websearchfield and enter few chars finishing with Return key the code does not execute as expected.

So the first question is: is it a bug?
Second question, how can I handle Return/Enter in regular WebSearchField?

Btw, I asked ChatGTP and it was suggesting using javascript with KeyDown event but I can’t find KeyDown event. Please help.

Can you share a sample project using dropbox, google drive or other sharing system?
I can’t replicate the problem.

There is no KeyDown event for Search Field in Web 2 (at least not at this time). I guess ChatGTP needs to be updated.

Edit: do you mean you want to know when Enter/Return was used instead of clicking the magnifying glass icon?

Do you have a “default button” in there?

xojo server apps are not multithreaded so to improve “performance” of web apps 2.0, xojo decided to remove many usefull events instead of improving the server…

To avoid the need of keypress events in textfields, now xojo emulates them with the event in a default button, but if you have another control that needs to respond to a enter presed, the events are going to overlap. it is a MESSS

Yes, that is a bug, xojo should stop the event propagation if it is inside a control that already implements it. If someone want to report it go for it.

ChatGTP is correct, but it meas the KeyDown in javascript. That is right, to have a simple KeyDown Event in xojo, you have to make your own custom control using javascript code and the xojo WebSDK.

Clicking on magnifying glass of the WebSearchField is trapped by Pressed event and this works fine.
However, people want to use web page with keyboard when typing in the search string, it is only a matter of pressing Enter/Return key right after (clicking on magnifying glass is simply not natural in this case).

Just to be clear, by search I mean calling the method to concatenate sql query and pass to the method to fetch data from the database off the server into the list and refreshing corresponding list control on the web page.

So what I want to happen is this: after typing the string and hitting Return/Enter key on the keyboard I want to fetch data into webcombobox, load the first record (if any records returned) and set the focus onto the webcombobox. Right now I can only achieve this with the mouse click on the magnifying glass on the websearchfield.

If I need to use javascript then I am ready to “get dirty”, however, I need to know how to do it. So if you can (or somebody) point me to a good demo I will appreciate this very much.

Greg, the Enter/Return is working correctly here on a simple test, that is why I asked for a sample project.

As Ivan said, if you also have a Default Button (the blue one) on the same page, your app will fire both (Search and Default button) pressed events. Maybe this is your problem?

Things to try:

Create a page property ignoreDefaultEnter As Boolean = False

In the “Enter” detection in the SearchField, when detected, set it to true and continue

In The Default button, if ignoreDefaultEnter, then set it to false (processed, continue), and just return, if not, do your default things.

Thanks for all the replies so far. The web page I am working on is pretty crowded, has 6 web containers with many controls (mimicking tab pane of the desktop app). I didn’t have any buttons with the default attribute turned on making it modal in behavior. However, I think the problem may have been related to dialog component subclassed from the webmodaldialog, I have removed it and used webmessage insteaad as superclass for it. The search field seems to be working now as advertised. Obviously I have more testing to do but at least now I am a little wiser. Thanks a lot and Happy Friday!