Kaz Miller
Kaz Miller

Reputation: 979

How to disable the enter key for a p:commandButton?

I have a p:commandButton that actually is the logout button. It is placed in the north p:layoutUnit and if I press the enter key in any form it always log me out. I dont want that button to respond the enter key. How to do that?

Upvotes: 5

Views: 4423

Answers (2)

Josef E.
Josef E.

Reputation: 2219

Nest the button within this form tag:

<h:form id="thisform" onkeypress="if( event.keyCode == 13){event.keyCode=0;}">

Upvotes: 5

user1983983
user1983983

Reputation: 4841

Put a hidden button with no action in the logout form and capture the enter key via p:defaultCommand.

<p:defaultCommand target="dummy"/>
<p:commandButton id="dummy" process="@none" global="false" style="display:none;"/> 

Upvotes: 7

Related Questions