Description:
I'm using Select2 for dropdown, and i'm trying to disable selected option in list. I wrote the code given bellow but it is not working. Is there any mistake in this code?
Code:
$("#Users").change(function () {
$(".select2-results .select2-results__option[aria-selected=true]").each(function () {
$(this).attr("disabled","disabled");
});
});
Html:
<div class="form-group">
@Html.Label("Send Mail To", new { @class = "control-label", @style= "position: absolute;margin-top:18px;" })
<a id="clearSelectedUsers" class="pull-right btn btn-primary M-B10">Clear</a>
@Html.DropDownListFor(m => m.Users, new SelectList(Model.Users, "Email", "Name"), "Select", new { multiple = "multiple", @class = "form-control" ,@disabled = "disabled" })
</div>
Script:
var usersSelect2 = $("#Users").select2(); usersSelect2.val(toBeSelectedManagers).trigger("change");