Disable options on select2 after specific one is selected
<p>I am using a select2 in my web site with 10 options let's say. So I have this js:</p>

<pre><code>$("#myselect").select2({ 
    maximumSelectionLength: 3
});
</code></pre>

<p>When the option 1 is selected I want to disable all the other options on the Select2. Somehow like skip the maximumSelectionLength and suddenly allow only one to be selected. But this should happen only if I select the option 1.</p>

<p>If I choose the option 2 for example I just need to deactivate the option 1. </p>

<p>So in general the option 1 needs to be excluded from the max of 3 selection if something else is selected, and should deactivate all the other options in case it is selected in the beginning. I hope I make it quite clear in the description.</p>

<p>Is something like this possible and how? </p>

<p>I tried this one></p>

<pre><code>if($("#myselect").val() == 1){
    $("#myselect").find("option").each(function(){
        if($(this).val() != 1){
            $(this).attr("disabled", "disabled");
        }
    });
}
</code></pre>

<p>and this actually adds the disabled attribute to all the option when the option 1 is selected, but not on the produced select2 html code, only on my initial html, so it does not actually work.</p>

<p>Thanks in advance</p>