jQuery UI Autocomplete: Never pop up?
Is there some way I can tell jQuery UI Autocomplete to never search? I could set minLength
really high I suppose, but there is a proper way to do it?
In case you're wondering, I'm manually triggering it with an onclick event instead.
How I add the onclick handler:
if(settings.showOnClick) {
$(this).bind('click.ajaxselect', function(e) {
if(!$(this).data('focusHandled') && !$(this).autocomplete('widget').is(':visible')) {
$(this).autocomplete('search','');
$(this).data('focusHandled',true);
} else {
$(this).data('focusHandled',false);
}
}).bind('focus.ajaxselect', function(e) {
if(!$(this).data('focusHandled') && e.hasOwnProperty('origin开发者_StackOverflow社区alEvent') && $(this).val() === this.defaultValue && !$(this).autocomplete('widget').is(':visible')) {
$(this).autocomplete('search','');
$(this).data('focusHandled',true);
} else {
$(this).data('focusHandled',false);
}
})
}
Set minLength
to whatever you want (probably 0 since you manually trigger). Then,
$( ".selector" ).autocomplete({
select: function(event, ui) {
... // do your thing
$( ".selector" ).autocomplete("disable");
}
});
$( ".clicker" ).click(function() {
... // do your thing
$( ".selector" ).autocomplete("enable");
});
Putting this in the search
callback seems to do mostly what I want:
search: function(e, ui) {
if(settings.minLength < 0 && e.hasOwnProperty('originalEvent')) return false;
// other code
return true;
},
Then if I set minLength
to less than 0, typing events won't trigger a search, but my manual click event still will. Focus events seem to get cancelled too, though. Trying to determine if I'm happy about that behaviour or not.
精彩评论