AutoComplete with forceSelection=true closes suggestion panel on click on the scrollbar
See original GitHub issueDescribe the bug
When an autocomplete has set forceSelection=true and a fixed scrollHeight, a click on the scrollbar closes the suggestion panel instead of scrolling the panel (if the current text matches one entry).
Reproducer
Take the test project and change the following two files:
TestView.java:
package org.primefaces.test;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import lombok.Data;
@Data
@Named
@ViewScoped
public class TestView implements Serializable {
private String txt5;
public List<String> completeText(String query) {
List<String> results = new ArrayList<>();
// just always add the numbers 0 to 49
for (int i = 0; i < 50; i++) {
results.add(String.valueOf(i));
}
return results;
}
public String getTxt5() {
return txt5;
}
public void setTxt5(String txt5) {
this.txt5 = txt5;
}
}
test.xhtml:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>PrimeFaces Test</title>
</h:head>
<h:body>
<h1>Force Selection Bug</h1>
<h:form id="frmTest">
<p:autoComplete id="acForce"
forceSelection="true"
value="#{testView.txt5}"
completeMethod="#{testView.completeText}"
scrollHeight="250"/>
</h:form>
</h:body>
</html>
To reproduce the bug:
- open page
- enter number between 0 and 49
- try to drag the scrollbar with the mouse to reach the suggestions at the bottom
- the panel closes. You can not scroll by dragging the scrollbar.
How to not reproduce the bug:
- open page
- enter something that ist not a number between 0 and 49 => Something which does NOT match any of the suggestions
- try to drag the scrollbar with the mouse to reach the suggestions at the bottom.
- It works
I believe the problem is in https://github.com/primefaces/primefaces/blob/master/primefaces/src/main/resources/META-INF/resources/primefaces/autocomplete/autocomplete.js in the “blur” part of “setupForceSelection” the current value (https://github.com/primefaces/primefaces/blob/1c3ec0f985dddee5b0102fc3a651589d01a20ece/primefaces/src/main/resources/META-INF/resources/primefaces/autocomplete/autocomplete.js#L1282) is checked against all items (https://github.com/primefaces/primefaces/blob/1c3ec0f985dddee5b0102fc3a651589d01a20ece/primefaces/src/main/resources/META-INF/resources/primefaces/autocomplete/autocomplete.js#L1286) which then forces a click - which in turn then closes the panel.
Expected behavior
What should happen: you can scroll and the panel stays open. forceSelection does work.
PrimeFaces edition
None
PrimeFaces version
12.0.0
Theme
No response
JSF implementation
Mojarra
JSF version
2.3
Java version
11
Browser(s)
No response
Issue Analytics
- State:
- Created 9 months ago
- Comments:6 (2 by maintainers)

Top Related StackOverflow Question
@melloware no, not yet. Maybe the forceSelection part needs some reworking. This seems to be more an issue in the general idea of the forceSelection than a simple bug. But I am happy that I could condense it down to the actual cause. This should give a good starting point for debugging.
Let me test this out.