Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How make select2 readonly?

I know that "readonly" feature does not exist for select2. Please check here. How do I achieve that? Any help would be appreciated. Thanks. Note: I cant use disabled. If I use disabled, I will not get the list of selected value.

like image 238
Rajesh Samui Avatar asked Feb 27 '18 11:02

Rajesh Samui


2 Answers

I guess that issue is resolved or may be available for higher version as this worked for me.

Please go through the example to make a select2 readonly here: Select 2

In js code:

$("select").select2("readonly", true);

You can put your own CSS like:

.select2-container.select2-container-disabled .select2-choice {
  background-color: #ddd;
  border-color: #a8a8a8;
}
like image 76
Manisha Avatar answered Nov 15 '22 10:11

Manisha


$('.js-example-basic-single').select2({
  disabled: true
});

Render a disabled attribute after the page loads resolved for me.

A reminder, a field with the disabled attribute is not sent on forms

like image 29
Victor Matuk Avatar answered Nov 15 '22 12:11

Victor Matuk