【问题标题】:p:selectOneMenu keeps focusp:selectOneMenu 保持焦点
【发布时间】:2017-10-26 13:57:14
【问题描述】:

Primefaces v6.1 在使用 p:selectOneMenu 时似乎存在一个错误,它在显示模态对话框时保持焦点。您可以使用向上/向下箭头键更改 selectOneMenu 选择。当我用 h:selectOneMenu 替换 p:selectOneMenu 时,它按预期工作。知道如何将焦点移到 input1 字段吗?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html
  xmlns="http://www.w3.org/1999/xhtml"   
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:p="http://primefaces.org/ui"  
  xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>      
</h:head>
<h:body>
  <h:form id="form">
     <!-- PF('statusWidget').blur();document.activeElement.blur(); -->
     <p:selectOneMenu id="status" widgetVar="statusWidget"
                   onchange="PF('dlg').show();" value="test1">
       <f:selectItem itemValue="test1" itemLabel="TEST_1"/>
       <f:selectItem itemValue="test2" itemLabel="TEST_2"/>
       <f:selectItem itemValue="test3" itemLabel="TEST_3"/>
     </p:selectOneMenu>
     <!-- onShow="document.activeElement.blur();" -->      
     <p:dialog widgetVar="dlg" modal="true" focus="input1">
       <p:inputText id="input1" widgetVar="test"/>
     </p:dialog>
   </h:form>
  </h:body>
</html>

【问题讨论】:

  • 你的意思是即使focus="input1"也无济于事?
  • @Kukeltje 对,即使使用 focus="input1" 也不起作用。

标签: jsf primefaces


【解决方案1】:

我已通过添加对 focus() 的延迟调用来解决此问题。

onchange="PF('dlg').show();setTimeout(function() { $('#form:input1').focus()  },10)"

【讨论】:

    猜你喜欢
    • 2012-05-12
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-11
    • 2020-03-18
    • 2011-04-22
    • 2017-07-19
    相关资源
    最近更新 更多