Here I am using p:autoComplete
tag in PrimeFaces 5.1, but I can't remove first highlighted/selected item from the suggestions list. How I can remove this ?
Asked
Active
Viewed 1,370 times
2

Hatem Alimam
- 9,968
- 4
- 44
- 56

Jasmin Bhatti
- 57
- 11
-
there is no any attribute found that we can configure this issue. I also tried solution from this [link](http://code.google.com/p/primefaces/issues/detail?id=4551) – Jasmin Bhatti Jan 07 '15 at 09:41
-
In that case, it's not selected it's highlighted you mean ? – Hatem Alimam Jan 07 '15 at 09:46
-
Like standard google search work, is it possible in this case ? – Jasmin Bhatti Jan 07 '15 at 10:16
-
See the answer which does the same! – Hatem Alimam Jan 07 '15 at 10:19
1 Answers
6
Since your "problem" comes from this particular line
,
firstItem.addClass('ui-state-highlight');
What happens here is when the suggestions are ready to show up the script highlights the first item of the list, so in your case you would just "unhighlight" that item.
I have created a small function that would do that on every AutoComplete you have, you can call it in your document.ready
or where ever you see suitable:
function removeHighlightedFirstItem() {
var oldAutoCompleteShowSuggestions = PrimeFaces.widget.AutoComplete.prototype.showSuggestions;
PrimeFaces.widget.AutoComplete.prototype.showSuggestions = function(query) {
//calling original ShowSuggestions
oldAutoCompleteShowSuggestions.apply(this, [query]);
//after ShowSuggestions
//remove first item highlight
var firstItem = this.items.eq(0);
firstItem.removeClass('ui-state-highlight');
}
}
The result would look like this:
Note: The feature you are requesting is available for 5.1.5, 5.0.14 and 5.2 by adding the autoHighlight = "false"
attribute to the component.

Hatem Alimam
- 9,968
- 4
- 44
- 56
-
-
How submit form on press enter key, currently I have to press ESC in auto-complete before press enter key, and then it submit form on press Enter ? – Sagar Koshti Jan 16 '15 at 08:16