Unhighlight first highlighted item from AutoComplete

…衆ロ難τιáo~ 提交于 2019-12-24 04:47:08

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/27816211/unhighlight-first-highlighted-item-from-autocomplete

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!