Ver Fonte

Added truth checks to avoid unnecessarily firing initSelection.

Signed-off-by: Igor Vaynberg <[email protected]>
Dean Sofer há 13 anos atrás
pai
commit
ad8fd257aa
1 ficheiros alterados com 2 adições e 2 exclusões
  1. 2 2
      select2.js

+ 2 - 2
select2.js

@@ -1448,7 +1448,7 @@
                 this.updateSelection(data);
             } else {
                 // val is an object. !val is true for [undefined,null,'']
-                if (this.opts.initSelection) {
+                if (this.opts.initSelection && val) {
                     that = this;
                     this.opts.initSelection(this.opts.element.val(val), function(data){
                         self.opts.element.val(!data ? "" : self.id(data));
@@ -1915,7 +1915,7 @@
                 });
                 this.updateSelection(data);
             } else {
-                if (this.opts.initSelection) {
+                if (this.opts.initSelection && val !== null) {
                     this.opts.initSelection(this.opts.element.val(val), function(newVal){
                         $(newVal).each(function () { data.push(self.id(this)); });
                         self.setVal(data);