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


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
, 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
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

look at my small implementation: