How to make Enter Key Press behave like Submit in JSF. It works with InputBoxes; but not with inputSecret boxes
I haven't seen this issue before. The chance is little that this behaviour is browser specific. Try in different kinds of browsers to exclude the one and other (IE6/7/8, FF, Safari, Chrome, etc). The chance is bigger that this is caused by a (poor) Javascript key event listener which incorrectly suppresses the enter key (for example a JS password validator which checks the entered characters).
If still in vain, just add the following onkeypress
to the h:form
:
<h:form onkeypress="if (event.keyCode == 13) this.submit();">
You need to take textareas into account however. If you have them, then you need to copy all onkeypress
events over the h:inputXXX
elements expect of textareas yourself.
I tried it with Chrome and It worked perfectly. Any suggestions to make it work in IE? I have only one form and one input element(InputSecret box) - As BaluC said it could be because of the "IE bug which wouldn't make the parent form to submit if there's only one input element"
I tried the onkeypress event of the form to make it work in IE and it's not working. Something is happening even before the onkeypress event of the form is called?
I tried adding an additional hiddenBox and it did not work either. But adding an additional inputBox or InputSecret box did make it work in IE. How to make it work without adding any additional visible input elements?
Hi All I made it work by placing an additional inputBox and hiding it using javascript. Let me know if you have any other suggestions Thanks baluC for pointing me in the right direction Jerry
There is an old specification that pops into my mind with this one. If you have a form that contains just ONE input field, the behaviour of submitting on the enter-key doesn't work in some versions of Internet Explorer. The easiest fix is to make sure you have more than one input field.
Other reasons for this problem include...
- Not having an input of type submit
- Having an input of type submit, but it isn't visible on the page (hidden or positioned off-page)
This behaviour is very specific to this browser.
MS Bug Report Here: