Skip to content

Commit b7c952a

Browse files
author
Igor Vaynberg
committed
ignore first empty option in selects when a placeholder is set
1 parent 09f24fd commit b7c952a

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

select2.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@
579579
opts.query = this.bind(function (query) {
580580
var data = { results: [], more: false },
581581
term = query.term,
582-
process;
582+
children, firstChild, process;
583583

584584
process=function(element, collection) {
585585
var group;
@@ -596,7 +596,17 @@
596596
}
597597
};
598598

599-
element.children().each2(function(i, elm) { process(elm, data.results); });
599+
children=element.children();
600+
601+
// ignore the placeholder option if there is one
602+
if (this.getPlaceholder() !== undefined && children.length > 0) {
603+
firstChild = children[0];
604+
if ($(firstChild).text() === "") {
605+
children=children.not(firstChild);
606+
}
607+
}
608+
609+
children.each2(function(i, elm) { process(elm, data.results); });
600610

601611
query.callback(data);
602612
});

0 commit comments

Comments
 (0)