Bladeren bron

ignore first empty option in selects when a placeholder is set

Igor Vaynberg 13 jaren geleden
bovenliggende
commit
b7c952a1a3
1 gewijzigde bestanden met toevoegingen van 12 en 2 verwijderingen
  1. 12 2
      select2.js

+ 12 - 2
select2.js

@@ -579,7 +579,7 @@
                 opts.query = this.bind(function (query) {
                 opts.query = this.bind(function (query) {
                     var data = { results: [], more: false },
                     var data = { results: [], more: false },
                         term = query.term,
                         term = query.term,
-                        process;
+                        children, firstChild, process;
 
 
                     process=function(element, collection) {
                     process=function(element, collection) {
                         var group;
                         var group;
@@ -596,7 +596,17 @@
                         }
                         }
                     };
                     };
 
 
-                    element.children().each2(function(i, elm) { process(elm, data.results); });
+                    children=element.children();
+
+                    // ignore the placeholder option if there is one
+                    if (this.getPlaceholder() !== undefined && children.length > 0) {
+                        firstChild = children[0];
+                        if ($(firstChild).text() === "") {
+                            children=children.not(firstChild);
+                        }
+                    }
+
+                    children.each2(function(i, elm) { process(elm, data.results); });
 
 
                     query.callback(data);
                     query.callback(data);
                 });
                 });