【问题标题】:Submitting form by hitting ENTER event in primefaces p:autoComplete通过在 primefaces p:autoComplete 中点击 ENTER 事件提交表单
【发布时间】:2015-03-06 04:19:34
【问题描述】:

下面是我的代码:

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

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

【问题讨论】:

  • 我也遇到了同样的问题,请帮帮我......
  • 我已经在 SO 上看到了完全相同的问题,但也没有回答......一种不能完全奏效的解决方法是添加 "”到表格中。如果您按 ESC 隐藏自动完成选择覆盖,您可以按 Enter 提交表单。不过,这仍然是一个问题……

标签: jsf-2 primefaces


【解决方案1】:

一个迟到的答案,但我会把它留在这里......

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

类似话题:Submit form with primefaces widgets on enter

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-19
    • 1970-01-01
    • 2013-10-18
    • 1970-01-01
    • 2016-10-01
    • 1970-01-01
    相关资源
    最近更新 更多