jQuery autocomplete 1.1: Show All Data on focus

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-07 04:06:53

问题


How to make this extension show all data on focus?. I have tried to change minChars to 0 but it only show when the input double clicked.

$("#month").autocomplete(months, {
        minChars: 0,
        max: 12,
        autoFill: true,
        mustMatch: true,
        matchContains: false,
        scrollHeight: 220,
        formatItem: function(data, i, total) {
            // don't show the current month in the list of values (for whatever reason)
            if ( data[0] == months[new Date().getMonth()] ) 
                return false;
            return data[0];
        }
    });

回答1:


You need to bind a focus event to the input and call the jQuery UI method as a result. Take a look at this js fiddle for an example

I added the following code:

$('#month').autocomplete({
    // Your current code
}).on('focus', function(event) {
    var self = this;
    $(self).autocomplete( "search", this.value);;
});

the value passed into the search method is what the autocomplete will look for.

How to search for all values on focus

If you want all available dropdowns leave it as "" but add minLength : 0 to the options object.

$('#month').autocomplete({
    minLength : 0
}).on('focus', function(event) {
    $(this).autocomplete("search", "");
});



回答2:


I recently had the same problem, due to this plugin is old (and deprecated), there is very little documentation available for this version.

This worked for me:

var __n_clicks = 0;

$("#autocomplete_input").autocomplete(data, {
    minChars: 0,
    ...
}).on('click', function(event) {
    if(__n_clicks < 1){
        __n_clicks++;
        $(this).click();
    }else {
        __n_clicks = 0;   
    }
});

executing "dblclick" didn't work either, it had to be 2 clicks.




回答3:


If you want some combobox with this plugin try this:

$('.lookup').on('click', function(event) {
var str =$(this).attr('id');
$('#'+str.slice(1)).focus().click().click();
});


来源:https://stackoverflow.com/questions/16874214/jquery-autocomplete-1-1-show-all-data-on-focus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!