admin管理员组文章数量:1417691
In option "source" I get with ajax the results + 1 custom note text with info about possible results. Like: "Show 2 of 3456 results". Its only a info for the user.
For the last entry in the -ul- list, I would not have processed the following events: keyup,keydown,pageup and pagedown.
For this, I have in option "open" set this:
open: function(event, ui) {
$("ul.ui-autoplete.ui-menu li:last").removeClass("ui-menu-item").removeAttr("role").html('Show 2 of 3456 results');
},
HTML now look like this:
<ul class="ui-autoplete ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox" aria-activedescendant="ui-active-menuitem" style="z-index: 1; top: 39px; left: 79px; display: block; width: 273px;"> <li class="ui-menu-item" role="menuitem"> <a class="ui-corner-all" tabindex="-1">Result 1</a> </li> <li class="ui-menu-item" role="menuitem"> <a class="ui-corner-all" tabindex="-1">Result 2</a> </li> <li class="">Show 2 of 3456 results</li> </ul>
This works if it at least gives minimum one real result, not only the last note text.
But what if no result is available and only the note text(last item) "No Results", then I get an error message in the events: keyup,keydown,pageup and pagedown.
Error in Firebug: item.offset() is null
<ul class="ui-autoplete ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox" aria-activedescendant="ui-active-menuitem" style="z-index: 1; top: 39px; left: 79px; display: block; width: 273px;"> <li class="">No Results</li> </ul>
What can I do to add a custom -li- to end of list and that is not selectable?
jQuery-UI 1.8.13
In option "source" I get with ajax the results + 1 custom note text with info about possible results. Like: "Show 2 of 3456 results". Its only a info for the user.
For the last entry in the -ul- list, I would not have processed the following events: keyup,keydown,pageup and pagedown.
For this, I have in option "open" set this:
open: function(event, ui) {
$("ul.ui-autoplete.ui-menu li:last").removeClass("ui-menu-item").removeAttr("role").html('Show 2 of 3456 results');
},
HTML now look like this:
<ul class="ui-autoplete ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox" aria-activedescendant="ui-active-menuitem" style="z-index: 1; top: 39px; left: 79px; display: block; width: 273px;"> <li class="ui-menu-item" role="menuitem"> <a class="ui-corner-all" tabindex="-1">Result 1</a> </li> <li class="ui-menu-item" role="menuitem"> <a class="ui-corner-all" tabindex="-1">Result 2</a> </li> <li class="">Show 2 of 3456 results</li> </ul>
This works if it at least gives minimum one real result, not only the last note text.
But what if no result is available and only the note text(last item) "No Results", then I get an error message in the events: keyup,keydown,pageup and pagedown.
Error in Firebug: item.offset() is null
<ul class="ui-autoplete ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox" aria-activedescendant="ui-active-menuitem" style="z-index: 1; top: 39px; left: 79px; display: block; width: 273px;"> <li class="">No Results</li> </ul>
What can I do to add a custom -li- to end of list and that is not selectable?
jQuery-UI 1.8.13
Share Improve this question edited May 31, 2011 at 11:06 user706420 asked May 31, 2011 at 11:02 user706420user706420 1,2153 gold badges14 silver badges25 bronze badges2 Answers
Reset to default 2I have found that this widget will plain if your li
elements don't contain an a
tag. I realize this makes it selectable, so you'll either have to extend the class a bit for your case or create a CSS rule that ensures the li
doesn't get a selected state (which is a bit of a hack, I admit)
Rather than messing with the CSS selectors, why not bind to the select
and change
events to inspect the custom data you're adding to the object (available via the ui.item
argument to those events)? You'd end up with something like this:
$(function() {
$("#acInput").autoplete({
source: availableTags,
select: function(event, ui) {
// if it's your info item, then
event.preventDefault();
},
change: function(event, ui) {
// if it's your info item, then
event.preventDefault();
}
});
});
Note that the preventDefault()
just stops that event. In certain instances (when using the keyboard to navigate the list), it will populate the input with the item's value. You'd want your testing to reset the value of the textbox if you determined that the item selected or the value about to be changed to was in fact your data item.
本文标签: javascriptjQuery autocomplete don39t select itemStack Overflow
版权声明:本文标题:javascript - jQuery autocomplete don't select item - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745275730a2651173.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论