I'm using jquery autocomplete
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script>
<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js'></script>
Everything is working Ok., but now I'm trying to add a minChars option which doesn't do anything. My code looks like this:
$( "#searchid" ).autocomplete({
source: "/autocomplete_url.php?more=1",
minChars:6,
开发者_高级运维 select: function(event, ui) {
$("#searchid").val(ui.item.value);
$("#formid").submit();
}
});
Everything is working, except it disregards the options I'm adding. Why/How can I debug the problem?
UPDATE: according to the answer below, I've moved to use minLength instead. I've tried adding in two different ways but it doesn't work :/ This is my "new" code:
$( ".selector" ).autocomplete({ minLength: 6 });
$( "#searchid" ).autocomplete({
source: "/autocomplete_url.php?more=1",
minLength:6,
select: function(event, ui) {
event.preventDefault();
$("#searchid").val(ui.item.value);
$("#formid").submit();
}
});
Thanks
It's not minChars
but minLength
see http://jqueryui.com/demos/autocomplete/#option-minLength
$( ".selector" ).autocomplete({ minLength: 0 });
Generally, if you want to manipulate the form element that the autocomplete itself is attached to, you should include a
event.preventDefault();
inside your select: function(event, ui){}
block. Otherwise the default autocomplete behaviour will conflict with your code, as it's also trying to set that value.
Make sure that your source returns JSON with the keys: id, value, and label. If it doesn't you'll need to use a callback function as your source. Check out this article on nettus:
http://net.tutsplus.com/tutorials/javascript-ajax/how-to-use-the-jquery-ui-autocomplete-widget/
精彩评论