admin管理员组文章数量:1430644
I have an odd problem with a jQuery UI autoplete. I want it so that when the text field gets focus, a list of all options in the autoplete es up. This works, but when selecting an item by clicking on it, the suggestions stay open. I want the suggestions list to disappear like autoplete normally works.
It works fine when you select the item with your keyboard, but when you click an item, the list just keeps reappearing again over and over again.
To make this problem weirder, the functionality works perfectly when just passing values manually. It only starts happening when I'm passing in a JSON source.
Any ideas!?
Working Code - ,js,output
$(document).ready(function(){
var test = [ { value: "1",label: "Google" }, { value: "2", label:"StackOverflow" }, { value: "3", label:"Microsoft" }, { value: "4", label:"Yahoo" } ];
$("input").autoplete({
source: test,
delay: 0,
minLength: 0,
select: function(event, ui) {
event.preventDefault();
$(this).val(ui.item.label).attr('title', ui.item.label);
}
}).focus(function () {
$(this).val('').autoplete("search");
});
});
Broken Code - ,js,output
$(document).ready(function(){
$("input").autoplete({
source: '',
delay: 0,
minLength: 0,
select: function(event, ui) {
event.preventDefault();
$(this).val(ui.item.label).attr('title', ui.item.label);
}
}).focus(function () {
$(this).val('').autoplete("search");
});
});
I have an odd problem with a jQuery UI autoplete. I want it so that when the text field gets focus, a list of all options in the autoplete es up. This works, but when selecting an item by clicking on it, the suggestions stay open. I want the suggestions list to disappear like autoplete normally works.
It works fine when you select the item with your keyboard, but when you click an item, the list just keeps reappearing again over and over again.
To make this problem weirder, the functionality works perfectly when just passing values manually. It only starts happening when I'm passing in a JSON source.
Any ideas!?
Working Code - http://jsbin./aFeceTe/1/edit?html,js,output
$(document).ready(function(){
var test = [ { value: "1",label: "Google" }, { value: "2", label:"StackOverflow" }, { value: "3", label:"Microsoft" }, { value: "4", label:"Yahoo" } ];
$("input").autoplete({
source: test,
delay: 0,
minLength: 0,
select: function(event, ui) {
event.preventDefault();
$(this).val(ui.item.label).attr('title', ui.item.label);
}
}).focus(function () {
$(this).val('').autoplete("search");
});
});
Broken Code - http://jsbin./uyOGUVU/6/edit?html,js,output
$(document).ready(function(){
$("input").autoplete({
source: 'http://jsbin./IdIXIRU/3/js',
delay: 0,
minLength: 0,
select: function(event, ui) {
event.preventDefault();
$(this).val(ui.item.label).attr('title', ui.item.label);
}
}).focus(function () {
$(this).val('').autoplete("search");
});
});
Share
Improve this question
asked Oct 4, 2013 at 12:03
BT643BT643
3,8555 gold badges38 silver badges56 bronze badges
1 Answer
Reset to default 3Try this
$(document).ready(function(){
var temp = true;
$("input").autoplete({
source: 'http://jsbin./IdIXIRU/3/js',
delay: 0,
minLength: 0,
select: function(event, ui) {
event.preventDefault();
$(this).val(ui.item.label).attr('title', ui.item.label);
temp = true;
return false;
}
}).focus(function () {
if(temp) {
$(this).autoplete("search");
temp = false;
}
});
});
SEE DEMO
本文标签: javascriptjQuery UI Autocomplete Suggestions Not Closing on SelectStack Overflow
版权声明:本文标题:javascript - jQuery UI Autocomplete Suggestions Not Closing on Select - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745516112a2661548.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论