Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


option attribute disabled="disabled" #480

wants to merge 4 commits into from

8 participants


Handle the disabled attribute of select options. Fixes #479


I would really like to see this behavior in select2.


The current version will break if Select2 is not attached to a <select> element.


@kevin-brown I'm not sure I understand, isn't Select2 always attached to a <select> and not to anything else?


Select2 can be attached to an <input type="hidden" /> for things like AJAX data and using a data array.

This implementation looks for result.element which is only present if it is attached to a <select> element.


Damn, this is a deal breaker for me at the moment and sadly I do not have time to fix it myself. Hope to see it fixed and merged soon. Thanks for the effort so far @loxK.


@ootoovak It will work fine if you only use Select2 attached to a <select> element. You just need to grab the code from this pull request. I'm pretty sure it is up to date with the current master.

If you attach it to an <input> tag... then you need to wait for the fix.


@kevin-brown cheers, I'll give it a go. I didn't look forward to rolling back to Chosen at this point in time.


Better do

disabled = result.element ? result.element[0].disabled : false;

to cover the case where it's not a <select>


By the transitive property, this would fix #157.

@ivaynberg ivaynberg closed this in 8e9a231
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 4 deletions.
  1. +3 −1 select2.css
  2. +4 −3 select2.js
4 select2.css
@@ -554,6 +554,8 @@ disabled look for already selected choices in the results dropdown
text-decoration: none;
+.select2-result-unselectable { color: #aaa }
.select2-offscreen {
position: absolute;
left: -10000px;
@@ -570,4 +572,4 @@ disabled look for already selected choices in the results dropdown
.select2-search input {
background-position: 100% -21px !important;
7 select2.js
@@ -704,24 +704,25 @@ the specific language governing permissions and limitations under the Apache Lic
populate=function(results, container, depth) {
- var i, l, result, selectable, compound, node, label, innerContainer, formatted;
+ var i, l, result, selectable, disabled, compound, node, label, innerContainer, formatted;
for (i = 0, l = results.length; i < l; i = i + 1) {
selectable=id(result) !== undefined;
+ disabled=result.element ? result.element[0].disabled : false;
compound=result.children && result.children.length > 0;
- node.addClass(selectable ? "select2-result-selectable" : "select2-result-unselectable");
+ node.addClass(selectable && !disabled ? "select2-result-selectable" : "select2-result-unselectable");
if (compound) { node.addClass("select2-result-with-children"); }
- formatted=opts.formatResult(result, label, query);
+ formatted=opts.formatResult(result, label, query, node);
if (formatted!==undefined) {
Something went wrong with that request. Please try again.