How can I dynamically make a select2 combobox read-only?
Here\'s what I\'ve tried so far:
$(\'...\').attr({\'reado
Solution from Select2 - Issue #3387 - Readonly Support:
select[readonly].select2 + .select2-container {
pointer-events: none;
touch-action: none;
.select2-selection {
background: #eee;
box-shadow: none;
}
.select2-selection__arrow,
.select2-selection__clear {
display: none;
}
}
Edit: for versions > 4.07
- as commenters below correctly pointed out:
select[readonly].select2-hidden-accessible + .select2-container {
pointer-events: none;
touch-action: none;
.select2-selection {
background: #eee;
box-shadow: none;
}
.select2-selection__arrow, select[readonly].select2-hidden-accessible + .select2-container .select2-selection__clear {
display: none;
}
}