Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit Kendo multiselect to 2 items selection

I want to limit kendo multiselect to 2 items selection. I see maxSelectedItems option can help me but not sure where to add this in the tag below. Any help would be appreciated.

<select class="k-widget multiselect" data-role="multiselect" id="CompSelect"
     data-placeholder=""
     data-value-primitive="true"
     data-text-field="CompNameId"
     data-value-field="CompId"
     data-bind="value: SelectedComps,
         source: CompaniesList,
         events: {
         change: onChange,
     }">
</select>
like image 757
CuriousBenjamin Avatar asked Oct 24 '25 09:10

CuriousBenjamin


2 Answers

You can set that easily like this:

$("#CompSelect").data("kendoMultiSelect").options.maxSelectedItems = 2;

The above code can be placed in a function for the dataBound event. That way, as soon as the data is bound to the MultiSelect it will set the maxSelectedItems.

like image 144
chiapa Avatar answered Oct 26 '25 20:10

chiapa


Also, check this link.

<select id="multiselect" multiple="multiple">
    <option>Item1</option>
    <option>Item2</option>
    <option>Item3</option>
    <option>Item4</option>
</select>
<script>
$("#multiselect").kendoMultiSelect({
    maxSelectedItems: 3 //only three or less items could be selected
});
</script>
like image 34
A-Sharabiani Avatar answered Oct 26 '25 22:10

A-Sharabiani