question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AutoComplete with forceSelection=true closes suggestion panel on click on the scrollbar

See original GitHub issue

Describe 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:

  1. open page
  2. enter number between 0 and 49
  3. try to drag the scrollbar with the mouse to reach the suggestions at the bottom
  4. the panel closes. You can not scroll by dragging the scrollbar.

How to not reproduce the bug:

  1. open page
  2. enter something that ist not a number between 0 and 49 => Something which does NOT match any of the suggestions
  3. try to drag the scrollbar with the mouse to reach the suggestions at the bottom.
  4. 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:open
  • Created 9 months ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
iki-haconcommented, Dec 9, 2022

@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.

0reactions
mellowarecommented, Dec 14, 2022

Let me test this out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scriptaculous Autocomplete list closes on scroll bar click
I was having the exact issue yesterday, but after doing some r&d I got a pretty handy fix for this. By default this...
Read more >
clicking on autocomplete scrollbar closes window #12 - GitHub
when the autocomplete results are too long, a scrollbar appears so the user can scroll through them, but clicking the scrollbar closes the ......
Read more >
AutoComplete Extender - Scroll bar causes results to close?
I have had a website running using a textbox, autocomplete extender, and autocompletedropdownpanel. Basically when a user starts typing a ...
Read more >
[#MDL-63198] Autocomplete suggestions list closes on scroll ...
Try to grab hold of the scrollbar and drag it. This removes the focus from the search input and after half a second...
Read more >
Clicking rapidly on Intellisense suggestion box scroll arrows ...
Clicking at about the rate of a double click on the scroll bar arrows closes the intellisense suggestion box, rather than scrolling.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found