Parcourir la source

a small tweak to empty string handling in select2.val(). issue #34

Igor Vaynberg il y a 13 ans
Parent
commit
d0caa9131c
1 fichiers modifiés avec 2 ajouts et 2 suppressions
  1. 2 2
      select2.js

+ 2 - 2
select2.js

@@ -1017,8 +1017,8 @@
                     });
                     });
                 this.updateSelection(data);
                 this.updateSelection(data);
             } else {
             } else {
-                // val is an object
-                this.opts.element.val((val === null || val === "") ? "" : val.id);
+                // val is an object. !val is true for [undefined,null,'']
+                this.opts.element.val(!val ? "" : val.id);
                 this.updateSelection(val);
                 this.updateSelection(val);
             }
             }
             this.setPlaceholder();
             this.setPlaceholder();