Shafizadeh Shafizadeh - 4 months ago 10
CSS Question

Is it possible to limit the number of autocomplete-box rows?

As you know,

autocomplete
attribute is used for
<input>
s by default. Something like this:

enter image description here

Ok, I can totally remove that attribute by setting it
off
:

<input type="email" name="email" autocomplete="off">
// ^^^^^^^^^^^^^^^^^^


But I don't want disable it completely. I just want to limit it to two rows. Currently it is six rows. Anyway, Is there any solution (even by JS) to limit the number of that box's rows?

Answer

You can specify array of autocomplete options using jQuery.

$("#email").autocomplete({
    source: function(request, response){
        var results = $.ui.autocomplete.filter(yourAutocompleteArray, request.term);
        response(results.slice(0, NUMBER_OF_ROWS_YOU_WANT));
    }
});
Comments