htmljquery-select2readonly

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.


Solution

  • 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;
    }