开发者

a4j Command Button get focus on pressing Enter Key

开发者 https://www.devze.com 2023-03-08 04:57 出处:网络
I have a4j command butt开发者_如何学编程on on my jsf page , when I press Enter Key anywhere in the page this command button gets the focus and excutes its action

I have a4j command butt开发者_如何学编程on on my jsf page , when I press Enter Key anywhere in the page this command button gets the focus and excutes its action

I want to prevent the button from getting focus when pressing Enter Key I tried to use onfocus="this.blur()" but it didn't work

Thanks in advance


<a4j:commandButton> acts as a submit button. Hence executes action when pressed enter.

When you see the code generated you will find like <input type="submit"/>

To ignore that you should use a command link and to look like button give a style button as follows:

.button {
    font: bold 11px Arial;
    text-decoration: none;
    background-color: #EEEEEE;
    color: #333333;
    padding: 2px 6px 2px 6px;
    border-top: 1px solid #CCCCCC;
    border-right: 1px solid #333333;
    border-bottom: 1px solid #333333;
    border-left: 1px solid #CCCCCC;
   }

If you still want to go with <a4j:commandButton> then you can prevent enter by using

 onkeypress="var keycode;
 if (window.event) { keycode = window.event.keyCode;}else {return true;}
 if (keycode == 13) {return false;}else {return true;}"

But this would cause like when you press enter even onfocus then it would not submit or call action, better not to use it

0

精彩评论

暂无评论...
验证码 换一张
取 消