Browse Source

Added example for hiding search

This also fixes a possible issue where the `< 0` fallback would
not be used because the `minimumResultsForSearch` check would
always return false and never load in the module.

This closes https://github.com/select2/select2/pull/3077.
Kevin Brown 10 years ago
parent
commit
5c9dc0e509

+ 1 - 1
dist/js/select2.amd.full.js

@@ -3838,7 +3838,7 @@ define('select2/defaults',[
         options.dropdownAdapter = SearchableDropdown;
       }
 
-      if (options.minimumResultsForSearch > 0) {
+      if (options.minimumResultsForSearch !== 0) {
         options.dropdownAdapter = Utils.Decorate(
           options.dropdownAdapter,
           MinimumResultsForSearch

+ 1 - 1
dist/js/select2.amd.js

@@ -3838,7 +3838,7 @@ define('select2/defaults',[
         options.dropdownAdapter = SearchableDropdown;
       }
 
-      if (options.minimumResultsForSearch > 0) {
+      if (options.minimumResultsForSearch !== 0) {
         options.dropdownAdapter = Utils.Decorate(
           options.dropdownAdapter,
           MinimumResultsForSearch

+ 1 - 1
dist/js/select2.full.js

@@ -4277,7 +4277,7 @@ define('select2/defaults',[
         options.dropdownAdapter = SearchableDropdown;
       }
 
-      if (options.minimumResultsForSearch > 0) {
+      if (options.minimumResultsForSearch !== 0) {
         options.dropdownAdapter = Utils.Decorate(
           options.dropdownAdapter,
           MinimumResultsForSearch

File diff suppressed because it is too large
+ 0 - 0
dist/js/select2.full.min.js


+ 1 - 1
dist/js/select2.js

@@ -4277,7 +4277,7 @@ define('select2/defaults',[
         options.dropdownAdapter = SearchableDropdown;
       }
 
-      if (options.minimumResultsForSearch > 0) {
+      if (options.minimumResultsForSearch !== 0) {
         options.dropdownAdapter = Utils.Decorate(
           options.dropdownAdapter,
           MinimumResultsForSearch

File diff suppressed because it is too large
+ 0 - 0
dist/js/select2.min.js


+ 33 - 1
docs/examples.html

@@ -486,7 +486,8 @@ $(".js-programmatic-multi-clear").on("click", function () { $exampleMulti.val(nu
 </script>
     </div>
   </section>
-  <section id="multiple_max" class="row">
+
+  <section id="multiple-max" class="row">
     <div class="col-md-4">
       <h1>Limiting the number of selections</h1>
       <p>Select2 multi-value select boxes can set restrictions regarding the maximum number of options selected.
@@ -509,6 +510,33 @@ $(".js-example-basic-multiple-limit").select2({
     </div>
   </section>
 
+  <section id="hide-search" class="row">
+    <div class="col-md-4">
+      <h1>Hiding the search box</h1>
+
+      <p>
+        Select2 allows you to hide the search box depending on the numbeer of
+        options which are displayed. In this example, we use the value
+        <code>Infinity</code> to tell Select2 to never display the search box.
+      </p>
+
+      <p>
+        <select class="js-example-basic-hide-search js-states form-control"></select>
+      </p>
+    </div>
+    <div class="col-md-8">
+      <h2>Example code</h2>
+
+      <pre data-fill-from=".js-code-hide-search"></pre>
+
+<script type="text/x-example-code" class="js-code-hide-search">
+$(".js-example-basic-hide-search").select2({
+  minimumResultsForSearch: Infinity
+});
+</script>
+    </div>
+  </section>
+
   <section id="events" class="row">
     <div class="col-md-4">
       <h1>Events</h1>
@@ -1089,6 +1117,10 @@ $.fn.select2.amd.require(
     matcher: oldMatcher(matchStart)
   });
 
+  $(".js-example-basic-hide-search").select2({
+    minimumResultsForSearch: Infinity
+  });
+
   $diacritics.select2();
 
   $language.select2({

+ 1 - 1
src/js/select2/defaults.js

@@ -147,7 +147,7 @@ define([
         options.dropdownAdapter = SearchableDropdown;
       }
 
-      if (options.minimumResultsForSearch > 0) {
+      if (options.minimumResultsForSearch !== 0) {
         options.dropdownAdapter = Utils.Decorate(
           options.dropdownAdapter,
           MinimumResultsForSearch

Some files were not shown because too many files changed in this diff