场景:我使用了autcomplete的组件和infront,我使用了一个带搜索图像的命令链接.
我的目的是在点击commandlink后将光标显示在自动完成中.
我的代码如下:
自动完成:
<p:autoComplete id="senderAutocomplete" widgetVar="senderInfo"
value="#{customerReviewLazyDataModel.customerReviewVO.senderVO}"
completeMethod="#{customerReviewLazyDataModel.searchOrganizations}"
var="senderVO"
itemValue="#{senderVO}" converter="organizationConverterForCustomerReview"
size="60">
Run Code Online (Sandbox Code Playgroud)
commandlink
<p:commandLink oncomplete="setFocus()" ajax="true">
<p:graphicImage value="/app-resources/themes/yob/images/search.png" style="margin-bottom: -4px;"></p:graphicImage>
</p:commandLink>
Run Code Online (Sandbox Code Playgroud)
js功能
function setFocus(){
document.getElementById("senderAutocomplete").focus();
}
Run Code Online (Sandbox Code Playgroud)
这个问题有什么解决方案吗?
您用于获取要聚焦的输入的 DOM 元素的 ID 是错误的。首先,您必须考虑表单的 id。另外 a 的输入的 idp:autoComplete
有一个后缀_input
。所以用这个:
document.getElementById("formId:senderAutocomplete_input").focus();
Run Code Online (Sandbox Code Playgroud)
您还应该设置process="@this"
,commandButton
因为您只是用它来聚焦autoComplete
。
归档时间: |
|
查看次数: |
3049 次 |
最近记录: |