在弹出窗口上按Enter键时,会触发登录页面上的提交按钮

时间:2015-02-07 14:54:57

标签: javascript html jsf-2 richfaces

我有一个带有两个提交按钮的页面,这也打开了一个带有另一个提交按钮的弹出窗口(id:addPopup)。每当按下Enter键时,就会触发登录页面上的第一个提交按钮,但是我想调用弹出窗口上的按钮。 这是弹出窗口中提交按钮的代码:

<a4j:commandButton id="continueButton" styleClass="btn btn-primary"  
                    value="Continue" 
                    action="#{optionsController.continue()}"
                    render="menuPanel addSection addOptionsPanel"
                    oncomplete="if(#{empty facesContext.messageList})#{rich:component('addPopup')}.hide();"
                    disabled="#{empty optionsController.addParcelId and  empty optionsController.addGridReference}"  />

我尝试过使用richfaces热键,但它不起作用并且页面被提交

<rich:hotKey selector="#addPopup" enabledInInput="true" key="return" preventDefault="true"/>

也尝试过使用

<script type="text/javascript">
$(document).bind('keydown', 'Return', function(e){
        key  = e.keyCode;
        if(key == 13){
            var continueBtn = document.getElementById('continueButton'));               
            continueBtn.click();
    }

});

但这也不起作用。关于我做错了什么或任何其他可行的方法的任何建议?

2 个答案:

答案 0 :(得分:1)

我设法通过使用此脚本来处理输入密钥:

<script type="text/javascript">
$(document).bind('keydown', 'Return', function(e){
        key  = e.keyCode;
        if(key == 13){  // Enter key pressed
            // Get button binding from backing bean.        
            var continueBtn = document.getElementById("#{optionsController.continueButton.clientId}");                 
            if(!continueBtn.disabled){
                continueBtn.click();
            }
            return false;
        }  
});  

还为支持bean中的continueButton添加了绑定,以及getter和setter

答案 1 :(得分:0)

尝试以自己的<h:form>呈现弹出内容,这样Enter就会触发您当前所在的表单。

<rich:popupPanel id="loginPopup" show="true">
    <h:form id="login" class="compact-form clearfix">

    </h:form> 
</rich:popupPanel>

rich:popupPanel中,您可以通过必须附加弹出窗口的属性domElementAttachment来决定。

希望它有所帮助...