浏览代码

Code samples for options affecting the dropdown

This is just code samples, most of this still needs readable (non-code)
documentation that actually explains what is going on with the options.
Kevin Brown 9 年之前
父节点
当前提交
ce2204cff0

+ 32 - 0
docs/_includes/options/dropdown/filtering.html

@@ -7,17 +7,49 @@
     Can Select2 wait until the user has typed a search term before triggering the request?
   </h3>
 
+<pre class="prettyprint">
+$('select').select2({
+  ajax: {
+    delay: 250 // wait 250 milliseconds before triggering the request
+  }
+});
+</pre>
+
   {% include options/not-written.html %}
 
   <h3>
     Select2 is allowing long search terms, can this be prevented?
   </h3>
 
+<pre class="prettyprint">
+$('select').select2({
+  maximumInputLength: 20 // only allow terms up to 20 characters long
+});
+</pre>
+
   {% include options/not-written.html %}
 
   <h3>
     I only want the search box if there are enough results
   </h3>
 
+<pre class="prettyprint">
+$('select').select2({
+  minimumResultsForSearch: 20 // at least 20 results must be displayed
+});
+</pre>
+
+  {% include options/not-written.html %}
+
+  <h3>
+    How can I permanently hide the search box?
+  </h3>
+
+<pre class="prettyprint">
+$('select').select2({
+  minimumResultsForSearch: Infinity
+});
+</pre>
+
   {% include options/not-written.html %}
 </section>

+ 6 - 0
docs/_includes/options/dropdown/placement.html

@@ -13,6 +13,12 @@
     Can I pick an element for the dropdown to be appended to?
   </h3>
 
+<pre class="prettyprint">
+$('select').select2({
+  dropdownParent: $('#my_amazing_modal')
+});
+</pre>
+
   {% include options/not-written.html %}
 
   <h3>

+ 12 - 0
docs/_includes/options/dropdown/selections.html

@@ -7,11 +7,23 @@
     Can I select the highlighted result when the dropdown is closed?
   </h3>
 
+<pre class="prettyprint">
+$('select').select2({
+  selectOnClose: true
+});
+</pre>
+
   {% include options/not-written.html %}
 
   <h3>
     Can I prevent the dropdown from closing when a result is selected?
   </h3>
 
+<pre class="prettyprint">
+$('select').select2({
+  closeOnSelect: false
+});
+</pre>
+
   {% include options/not-written.html %}
 </section>