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

冷暖自知 提交于 2019-12-23 19:39:30

问题


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?


回答1:


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;"/> 



回答2:


Nest the button within this form tag:

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


来源:https://stackoverflow.com/questions/24142033/how-to-disable-the-enter-key-for-a-pcommandbutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!