WebTextField and the ENTER key

I tried to find the answer here but didn’t understand one that I saw involving jquery. How can I monitor the keystokes in a webtextfield and check for the ENTER key being pressed. Used to do this with keydown even in a windows textfield.

WebTextField key events are not part of Web 2. You can use a Default button that will fire if Enter key is pressed in any of the WebTextFields of your page.

If you need to detect the Enter key on a WebTextField, you can use something like this:

Thank you @AlbertoD. I followed the sample that Liam has in the link you sent me and it worked perfectly.


New version with the ability to select the keys you want to fire

Just for clarity…

There are some special behaviors in Web 2 when it comes to buttons. Just like on Desktop projects, Buttons can be specified as Cancel or Default. When you do this and the user presses the ESC or ENTER/RETURN key (respectively) the framework will search for the first button that is visible and enabled to “push” on the user’s behalf. It makes coding the “enter key to submit” very easy.

@Greg_O That’s one specific case.

Simple login page. Username and password text fields. You have a cancel and login buttons. I’ve found most users fill type their username and hit enter instead of tab to the next field. Therefore requiring the enter key to initialize an event to allow the ability to add custom code and to swap to the password field.

Also, detecting only previously selected key events reduces messages between session and server and allows a wider range of keyevent capturing options. When this has been brought up in the past it was always an issue with increasing traffic between session and server thereby decreasing performance of the WebApp, but allowing the user to select the keyevent options lets them decide on performance

1 Like

Oh I understand. I put it out there for people who didn’t know.

That’s not my experience.

1 Like

That is not expected behavior in a web page. It’s not even expected behavior in a desktop app.

Like I said “I’ve found” as in the users that use the apps I’ve made. Enter swaps to the next field. I dont care if thats not expected. Was just mentioning it to show a use case for needing keypress events on certain keys

1 Like

Just literally helping the OP. Everyone on this forum likes to jump all over people for suggesting things not in the norm or trying to restructure the question. Just help try and solve the issue and not try and nit pick

1 Like