Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit select2 results

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?

like image 329
Vassilis Avatar asked Feb 04 '13 10:02

Vassilis


2 Answers

see maximumSelectionSize option, if you want to limit the number of results that can be selected

like image 76
igor.vaynberg Avatar answered Nov 15 '22 06:11

igor.vaynberg


How about

tags = tags.slice(0, 5);

wherever relevant in your context.

like image 26
Peter Herdenborg Avatar answered Nov 15 '22 06:11

Peter Herdenborg