我想在一定数量的字符后阻止jquery自动完成。
目的是,我有一个订单号列表,其中包含最后一个后缀,并且始终是已知的。每个订单号是12位数字,3位数字作为已知后缀。我希望在5个字符后开始自动完成,并且我使用minLength: 5
实现了,但我无法将最大数量指定为8。
由于最后3位数字始终是已知的,我希望它仅搜索前8位数字,就像您知道前9位数字一样,然后您就知道完整的订单号码。已经
我尝试使用maxLength:8
,但它不起作用。自动完成功能即使在8位数之后也会激活。
请帮忙。非常感谢提前!!
答案 0 :(得分:1)
将source
选项设置为函数:
$('#myInput').autocomplete({
...
source: function(pattern, response){
if (pattern.length > 8) {
//don't do anything
return;
}
//else : fetch your data, and call the 'response' callback
$.ajax({
url: 'my/autcomplete/url',
dataType: 'json',
data: {"pattern": pattern}
success: function(data){
// build a string array form your data,
// or an array of {label, value} objects (see the doc)
response(data);
}
});
}