Best way to: On Enter Key Pressed on field A focus field B

Hello,

What is the best way to do this?

In pratice i would like to inject this javascript code on textfield A:

onkeydown=“if (event.keyCode == 13) document.getElementById(‘txtFieldB’).focus()”

I know that if i put
txtFieldA.setImmediate(true)
, i can set focus to txfFieldB on txtFieldA Value Change.
But, this is the best way? There is other way?

Thanks in advance

I believe you could also add a shortcut action handler on a Form or Panel that contains the field, handling the Enter key press there and changing the focus based on the selected field. See ShortcutAction and Panel.addActionHandler().

You could take a look e.g. at
this example
and
this test case
to see how this can be done; there are probably also better examples somewhere.

Thanks Henri,

I understand… but how do i get the selected field?

If I remember correctly, the target of an action is the component on which the action occurred except for some data components (table and tree, at least), where it is the item id.

This should be clarified in the javadoc - added a mention of that to the javadoc ticket
#4690
.

Hello!
look at my small implementation: http://www.alfrescodev.com/vaadin-enter-instead-tab