Skip to content

Commit 20950e0

Browse files
committed
Update select2.js
Fixed issues with select2 and disabled options, most of it having to do with incorrectly determining the index of an option when disabled options were being displayed.
1 parent 660c402 commit 20950e0

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

select2.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ the specific language governing permissions and limitations under the Apache Lic
633633
search.bind("blur", function () { search.removeClass("select2-focused");});
634634

635635
this.dropdown.delegate(resultsSelector, "mouseup", this.bind(function (e) {
636-
if ($(e.target).closest(".select2-result-selectable:not(.select2-disabled)").length > 0) {
636+
if ($(e.target).closest(".select2-result-selectable:visible").length > 0) {
637637
this.highlightUnderEvent(e);
638638
this.selectHighlighted(e);
639639
} else {
@@ -1079,7 +1079,7 @@ the specific language governing permissions and limitations under the Apache Lic
10791079
return;
10801080
}
10811081

1082-
children = results.find(".select2-result-selectable");
1082+
children = results.find(".select2-result:visible");
10831083

10841084
child = $(children[index]);
10851085

@@ -1107,13 +1107,13 @@ the specific language governing permissions and limitations under the Apache Lic
11071107

11081108
// abstract
11091109
moveHighlight: function (delta) {
1110-
var choices = this.results.find(".select2-result-selectable"),
1110+
var choices = this.results.find(".select2-result:visible"),
11111111
index = this.highlight();
11121112

11131113
while (index > -1 && index < choices.length) {
11141114
index += delta;
11151115
var choice = $(choices[index]);
1116-
if (choice.hasClass("select2-result-selectable") && !choice.hasClass("select2-disabled")) {
1116+
if (choice.hasClass("select2-result-selectable") && !choice.hasClass("select2-disabled") && !choice.hasClass("select2-selected")) {
11171117
this.highlight(index);
11181118
break;
11191119
}
@@ -1122,7 +1122,7 @@ the specific language governing permissions and limitations under the Apache Lic
11221122

11231123
// abstract
11241124
highlight: function (index) {
1125-
var choices = this.results.find(".select2-result-selectable").not(".select2-disabled");
1125+
var choices = this.results.find(".select2-result:visible");
11261126

11271127
if (arguments.length === 0) {
11281128
return indexOf(choices.filter(".select2-highlighted")[0], choices.get());
@@ -1140,14 +1140,14 @@ the specific language governing permissions and limitations under the Apache Lic
11401140

11411141
// abstract
11421142
countSelectableResults: function() {
1143-
return this.results.find(".select2-result-selectable").not(".select2-disabled").length;
1143+
return this.results.find(".select2-result-selectable").not(".select2-disabled").not(".select2-selected").length;
11441144
},
11451145

11461146
// abstract
11471147
highlightUnderEvent: function (event) {
11481148
var el = $(event.target).closest(".select2-result-selectable");
11491149
if (el.length > 0 && !el.is(".select2-highlighted")) {
1150-
var choices = this.results.find('.select2-result-selectable');
1150+
var choices = this.results.find('.select2-result');
11511151
this.highlight(choices.index(el));
11521152
} else if (el.length == 0) {
11531153
// if we are over an unselectable item remove al highlights
@@ -1350,10 +1350,10 @@ the specific language governing permissions and limitations under the Apache Lic
13501350
// abstract
13511351
selectHighlighted: function (options) {
13521352
var index=this.highlight(),
1353-
highlighted=this.results.find(".select2-highlighted").not(".select2-disabled"),
1354-
data = highlighted.closest('.select2-result-selectable').data("select2-data");
1353+
highlighted=this.results.find(".select2-highlighted:visible"),
1354+
data = highlighted.closest('.select2-result:visible').data("select2-data");
13551355
if (data) {
1356-
highlighted.addClass("select2-disabled");
1356+
highlighted.addClass("select2-selected");
13571357
this.highlight(index);
13581358
this.onSelect(data, options);
13591359
}
@@ -1698,7 +1698,7 @@ the specific language governing permissions and limitations under the Apache Lic
16981698

16991699
// find the selected element in the result list
17001700

1701-
this.results.find(".select2-result-selectable").each2(function (i, elm) {
1701+
this.results.find(".select2-result:visible").each2(function (i, elm) {
17021702
if (equal(self.id(elm.data("select2-data")), self.opts.element.val())) {
17031703
selected = i;
17041704
return false;

0 commit comments

Comments
 (0)