Blame view

bower_components/select2/docs/_includes/options-old/setting-default-options.html 1.35 KB
f6e211e4   Administrator   finish work part 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  <section>
    <h1 id="setting-default-options">Setting default options</h1>
  
    <p>
      In some cases, you need to set the default options for all instances of
      Select2 in your web application. This is especially useful when you are
      migrating from past versions of Select2, or you are using non-standard
      options <a href="#amd">like custom AMD builds</a>. Select2 exposes the
      default options through <code>$.fn.select2.defaults</code>, which allows
      you to set them globally.
    </p>
  
    <p>
      When setting options globally, any past defaults that have been set will
      be overriden. Default options are only used when an option is requested
      that has not been set during initialization.
    </p>
  
    <p>
      <strong>You can set default options</strong> by calling
      <code>$.fn.select2.defaults.set("key", "value")</code>. The key that is
      set should take the same format as keys set using
      <a href="#data-attributes">HTML <code>data-*</code> attributes</a> which
      means that two dashes (<code>--</code>) will be replaced by a level of
      nesting, and a single dash (<code>-</code>) will convert it to a camelCase
      string.
    </p>
  
  <pre class="prettyprint">
  $.fn.select2.defaults.set("theme", "classic");
  </pre>
  
    <p>
      <strong>You can reset the default options</strong> by calling
      <code>$.fn.select2.defaults.reset()</code>.
    </p>
  </section>