通过单击primefaces p:autoComplete中的ENTER事件提交表单 [英] Submitting form by hitting ENTER event in primefaces p:autoComplete

查看:96
本文介绍了通过单击primefaces p:autoComplete中的ENTER事件提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码:

<h:form>   
  <p:autoComplete id="autoCompleteID" value="#{myBean.item}"  
                       completeMethod="#{myBean.completeMethod}"    
  </p:autoComplete>
  <h:commandButton action="#{myBean.searchRelatedItems}"/>
</h:form>

在这里,我的情况就像标准的Google搜索一样,我可以在建议中看到相关的项目,还可以根据在p:autoComplete文本字段中键入的文本来重定向另一个页面.单击Button可以正常工作,但我也想通过在p:autoComplete文本字段中按ENTER来实现.

Here my scenario is like standard Google search, I can see related Items in suggestion and also redirect another page based on text typed in p:autoComplete text field. Its works fine by click on Button, but I also want to achieve by hitting ENTER in p:autoComplete text field.

推荐答案

一个较晚的答案,但我将其留在这里...

A late answer, but I will just leave it here...

  • 尝试使用Primefaces命令按钮,它是p:commandButton,而不是h:commandButton.
  • 确保commandButton的属性类型为提交"而不是按钮","submit"是Primefaces中的默认设置.
  • 最后一种(但我认为很讨厌)的解决方案是将id放置在commandButton上,例如"search-button",并将id放置在h:form上,例如"searchForm",然后将以下内容放置在p:autoComplete或h处: :form onkeyup="if (event.keyCode === 13) { document.getElementById('searchForm:search-button').click(); return false; }"

类似的主题:提交带有Enter上的primefaces小部件的表单

这篇关于通过单击primefaces p:autoComplete中的ENTER事件提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆