Il Recapito Espresso
Il Recapito Espresso

Reputation: 137

jquery autocmplete set max items

I am going to use the jquery autocomplete plugin and i will to set the max items to display. Searching on google I found that there is the "max" option to set at the number of items that I want to show, but it do not work.

I use jquery-ui-1.8.21 version.

$("#test").autocomplete({
     source:myarray,
     max:5
});

Thanks

Upvotes: 0

Views: 6069

Answers (3)

Azam Alvi
Azam Alvi

Reputation: 7055

You can do it by this way Into your ajax success function change according this

success: function (data) {
      response($.map(data.slice(0,4), function (item) {
           return {
            label: item.name,
            value: item.name
        }
    }));
}

Upvotes: 0

Bishnu Paudel
Bishnu Paudel

Reputation: 2079

Add this to your CSS .ui-autocomplete { height: 100px; overflow-y: scroll; overflow-x: hidden;} By changing the height you can limit the number of items visible to the user.

Upvotes: 1

Anonymous
Anonymous

Reputation: 707

Where did you read that? I can't find max in autocomplete's documentation under "options" tab at the bottom.

Although, there's an example how to set the maximum height for better user experience. But if you really want first n elements from that array just use slice() method from pure JavaScript.

Upvotes: 2

Related Questions