0

Is it possible to add specific behaviour when tab button is pressed?
For example, how to go to the next empty field or to specific field on the form?

I'm already using onkeypress="if (event.keyCode == 13) {//do something}" for overriding/handling enter button, so I wonder whether it is possible to do something similar with tab button?

Emil Sierżęga
  • 1,785
  • 2
  • 31
  • 38
endcode
  • 1
  • 2
  • Well your question is not very clear, but primefaces tab have some ajax events, those are `tabChange` and `tabClose` maybe that could help you. – Ouerghi Yassine Aug 30 '16 at 09:11
  • Thx and sorry if question is confusing. I'm talking about Tab button (keyboard Tab button) and not tab like component in TabView. So the question is, can I specify to which field exactly focus should go when I press Tab button on keyboard. – endcode Aug 30 '16 at 09:43
  • aw sorry, i misunderstood u, so html have this attribute called `tabindex` have a look at it http://www.w3schools.com/tags/att_global_tabindex.asp – Ouerghi Yassine Aug 30 '16 at 10:35

1 Answers1

0

KeyCode for Tab is 9. So with your code it will be:

onkeypress="if (event.keyCode == 9) {//do something}"

You can also read this topic.


Selecting the first empty input could have nothing to do with the Tab. With jQuery you can use i.e:

$('#formId').find("input:[value='']:visible:enabled").first().focus();

You can find many examples on Stack Overflow i.e. here and here.

Community
  • 1
  • 1
Emil Sierżęga
  • 1,785
  • 2
  • 31
  • 38