开发者

jQuery Autocomplete minLength and Return Values

I'm implementing autocomplete, but it's firing on the first keypress and it's开发者_如何学编程 also returning the value to the textbox, which I don't want as I'm using it as a method to prevent duplicates.

I'm using jQuery 1.6.

Any idea on how to correct this?

$("#groupname").autocomplete("resources/getallgroups.php", {
    minLength: 2,
    select: function(event, ui) {
        return false;
    }
});


What autocomplete library are you using? The best one would be jQuery UI in which case you want to change your code to this:

$("#groupname").autocomplete({
    source: "resources/getallgroups.php",
    minLength: 2,
    select: function(event, ui) {
        return false;
    }
});

All the docs are here: http://jqueryui.com/demos/autocomplete/


Thought this should be a separate answer...

According to the documentation minLength should be minChars. Also I don't see an option for a select callback anywhere but you might be able to use the result event like so:

$("#groupname").autocomplete("resources/getallgroups.php", {
  minChars: 2
}).result(function(event, data, formatted) { 
  return FALSE;
});

Hope that helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜