Wildan Muhlis
Wildan Muhlis

Reputation: 1603

jQuery autocomplete 1.1: Show All Data on focus

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];
        }
    });

Upvotes: 3

Views: 9001

Answers (4)

Xiel
Xiel

Reputation: 51

    $(".autocomplete_input").autocomplete(availableTags, {
        minChars: 0,
    }).focus(function(event) {
        $(this).click();
    });

this could also work for one click only, but it's best to just switch plugin entirely.

Upvotes: 0

Kontel
Kontel

Reputation: 1

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();
});

Upvotes: 0

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.

Upvotes: 0

David Barker
David Barker

Reputation: 14620

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", "");
});

Upvotes: 10

Related Questions