How to limit Kendo multiselect to 2 items

I want to limit xendo multi-selection to 2 items. I see that the maxSelectedItems parameter 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>

      

+3


source to share


2 answers


You can easily install like this:

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

      



The above code can be placed in a function for the dataBound event. This way, once the data is bound to MultiSelect

, it will set maxSelectedItems

.

+4


source


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>

      

0


source







All Articles