Reputation: 2841
I am using the excellent select2 jquery plugin to select tags.
I am not able to find a way to limit the results (say to first 5 only).
My code:
var tags = []; // this array is filled with user's tags
$("#tags").select2({
minimumInputLength: 2,
placeholder: 'tags',
tags: tags,
tokenSeparators: [",", " "],
closeOnSelect: false
});
Any ideas?
Upvotes: 5
Views: 6208
Reputation: 39
If you're getting results via a database call then you could edit the LIMIT statement in the SQL query. For example, this would only return the first 10 results:
SELECT id,categories FROM wikitags WHERE categories LIKE :term ORDER BY
categories ASC LIMIT 0,10
If a remote call then appreciate the solution much trickier.
Upvotes: -1
Reputation: 1453
see maximumSelectionSize
option, if you want to limit the number of results that can be selected
Upvotes: 5
Reputation: 5962
How about
tags = tags.slice(0, 5);
wherever relevant in your context.
Upvotes: 1