Submitting form by hitting ENTER event in primefaces p:autoComplete

吃可爱长大的小学妹 提交于 2019-12-24 03:54:10

问题


Below is my code:

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

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.


回答1:


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

  • Try using a Primefaces commandButton, it is p:commandButton, not h:commandButton.
  • Make sure the attribute type of the commandButton is "submit" and not "button", "submit" is the default in Primefaces.
  • Lastly a certain (but nasty I believe) solution is to put an id at the commandButton like "search-button" and an id at the h:form like "searchForm" and put the following at the p:autoComplete or h:form onkeyup="if (event.keyCode === 13) { document.getElementById('searchForm:search-button').click(); return false; }"

Similar topic: Submit form with primefaces widgets on enter



来源:https://stackoverflow.com/questions/27833562/submitting-form-by-hitting-enter-event-in-primefaces-pautocomplete

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