I have select2 multi select field in my form where I want to remove the selected option from the dropdown list after it is selected and again add it to the list if it is removed
Another approach to hide the selected values, is to use the dropdown templateResult option to return null
when the value is marked as selected.
function hideSelected(value) {
if (value && !value.selected) {
return $('' + value.text + '');
}
}
$(document).ready(function() {
$('#dynamicAttributes').select2({
allowClear: true,
placeholder: {
id: "",
placeholder: "Leave blank to ..."
},
minimumResultsForSearch: -1,
width: 600,
templateResult: hideSelected,
});
});