examples.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. ---
  2. layout: default
  3. title: Examples - Select2
  4. slug: examples
  5. ---
  6. <script type="text/javascript" src="dist/js/i18n/es.js"></script>
  7. <div class="container">
  8. <section id="basic" class="row">
  9. <div class="col-md-4">
  10. <h1>The basics</h1>
  11. <p>
  12. Select2 can take a regular select box like this...
  13. </p>
  14. <p>
  15. <select class="js-states form-control"></select>
  16. </p>
  17. <p>
  18. and turn it into this...
  19. </p>
  20. <p>
  21. <select class="js-example-basic-single js-states form-control"></select>
  22. </p>
  23. </div>
  24. <div class="col-md-8">
  25. <h2>Example code</h2>
  26. <pre class="code" data-fill-from=".js-code-basic"></pre>
  27. <script type="text/x-example-code" class="js-code-basic">
  28. $(document).ready(function() {
  29. $(".js-example-basic-single").select2();
  30. });
  31. <select class="js-example-basic-single">
  32. <option value="AL">Alabama</option>
  33. ...
  34. <option value="WY">Wyoming</option>
  35. </select>
  36. </script>
  37. </div>
  38. </section>
  39. <section id="multiple" class="row">
  40. <div class="col-md-4">
  41. <h1>Multiple select boxes</h1>
  42. <p>
  43. Select2 also supports multi-value select boxes. The select below is declared with the <code>multiple</code> attribute.
  44. </p>
  45. <p>
  46. <select class="js-example-basic-multiple js-states form-control" multiple="multiple"></select>
  47. </p>
  48. </div>
  49. <div class="col-md-8">
  50. <h2>Example code</h2>
  51. <pre data-fill-from=".js-code-multiple"></pre>
  52. <script type="text/x-example-code" class="js-code-multiple">
  53. $(".js-example-basic-multiple").select2();
  54. <select class="js-example-basic-multiple" multiple="multiple">
  55. <option value="AL">Alabama</option>
  56. ...
  57. <option value="WY">Wyoming</option>
  58. </select>
  59. </script>
  60. </div>
  61. </section>
  62. <section id="placeholders" class="row">
  63. <div class="col-md-4">
  64. <h1>Placeholders</h1>
  65. <p>
  66. A placeholder value can be defined and will be displayed until a selection is made.
  67. </p>
  68. <p>
  69. <select class="js-example-placeholder-single js-states form-control">
  70. <option></option>
  71. </select>
  72. </p>
  73. <p>
  74. This works for multiple select boxes as well.
  75. </p>
  76. <p>
  77. <select class="js-example-placeholder-multiple js-states form-control" multiple="multiple"></select>
  78. </p>
  79. </div>
  80. <div class="col-md-8">
  81. <h2>Example code</h2>
  82. <pre data-fill-from=".js-code-placeholder"></pre>
  83. <script type="text/javascript" class="js-code-placeholder">
  84. $(".js-example-placeholder-single").select2({
  85. placeholder: "Select a state",
  86. allowClear: true
  87. });
  88. $(".js-example-placeholder-multiple").select2({
  89. placeholder: "Select a state"
  90. });
  91. </script>
  92. </div>
  93. </section>
  94. <section id="data-array" class="row">
  95. <div class="col-md-4">
  96. <h1>Loading array data</h1>
  97. <p>
  98. Select2 provides a way to load the data from a local array.
  99. </p>
  100. <p>
  101. <select class="js-example-data-array form-control"></select>
  102. </p>
  103. <p>
  104. You can provide initial selections with array data by providing the
  105. option tag for the selected values, similar to how it would be done for
  106. a standard select.
  107. </p>
  108. <p>
  109. <select class="js-example-data-array-selected form-control">
  110. <option value="2" selected="selected">duplicate</option>
  111. </select>
  112. </p>
  113. </div>
  114. <div class="col-md-8">
  115. <h2>Example code</h2>
  116. <pre data-fill-from=".js-code-data-array"></pre>
  117. <script type="text/x-example-code" class="js-code-data-array">
  118. var data = [{ id: 0, text: 'enhancement' }, { id: 1, text: 'bug' }, { id: 2, text: 'duplicate' }, { id: 3, text: 'invalid' }, { id: 4, text: 'wontfix' }];
  119. $(".js-example-data-array").select2({
  120. data: data
  121. })
  122. $(".js-example-data-array-selected").select2({
  123. data: data
  124. })
  125. <select class="js-example-data-array-selected"></select>
  126. <select class="js-example-data-array-selected">
  127. <option value="2" selected="selected">duplicate</option>
  128. </select>
  129. </script>
  130. </div>
  131. </section>
  132. <section id="data-ajax" class="row">
  133. <div class="col-md-12">
  134. <h1>Loading remote data</h1>
  135. <p>
  136. Select2 comes with AJAX support built in, using jQuery's AJAX methods.
  137. In this example, we can search for repositories using GitHub's API.
  138. </p>
  139. <p>
  140. <select class="js-example-data-ajax form-control">
  141. <option value="ivaynberg/select2" selected="selected">ivaynberg/select2</option>
  142. </select>
  143. </p>
  144. <p>
  145. When using Select2 with remote data, the HTML required for the
  146. <code>select</code> is the same as any other Select2. If you need to
  147. provide default selections, you just need to include an
  148. <code>option</code> for each selection that contains the value and text
  149. that should be displayed.
  150. </p>
  151. <pre data-fill-from=".js-code-data-ajax-html"></pre>
  152. <p>
  153. You can configure how Select2 searches for remote data using the
  154. <code>ajax</code> option. More information on the individual options
  155. that Select2 handles can be found in the
  156. <a href="options.html#ajax">options documentation for <code>ajax</code></a>.
  157. </p>
  158. <pre data-fill-from=".js-code-data-ajax"></pre>
  159. <p>
  160. Select2 will pass any options in the <code>ajax</code> object to
  161. jQuery's <code>$.ajax</code> function, or the <code>transport</code>
  162. function you specify.
  163. </p>
  164. <script type="text/x-example-code" class="js-code-data-ajax">
  165. $(".js-data-example-ajax").select2({
  166. ajax: {
  167. url: "https://api.github.com/search/repositories",
  168. dataType: 'json',
  169. delay: 250,
  170. data: function (params) {
  171. return {
  172. q: params.term, // search term
  173. page: params.page
  174. };
  175. },
  176. processResults: function (data, page) {
  177. // parse the results into the format expected by Select2.
  178. // since we are using custom formatting functions we do not need to
  179. // alter the remote JSON data
  180. return data.items;
  181. },
  182. cache: true
  183. },
  184. minimumInputLength: 1,
  185. templateResult: formatRepo, // omitted for brevity, see the source of this page
  186. templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
  187. });
  188. </script>
  189. <script type="text/x-example-code" class="js-code-data-ajax-html">
  190. <select class="js-data-example-ajax">
  191. <option value="ivaynberg/select2" selected="selected">ivaynberg/select2</option>
  192. </select>
  193. </script>
  194. </div>
  195. </section>
  196. <section id="disabled" class="row">
  197. <div class="col-md-4">
  198. <h1>Disabled mode</h1>
  199. <p>
  200. Select2 will response the <code>disabled</code> attribute on
  201. <code>&lt;select&gt;</code> elements. You can also initialize Select2
  202. with <code>disabled: true</code> to get the same effect.
  203. </p>
  204. <p>
  205. <select class="js-example-disabled js-states form-control" disabled="disabled"></select>
  206. </p>
  207. <p>
  208. <select class="js-example-disabled-multi js-states form-control" multiple="multiple" disabled="disabled"></select>
  209. </p>
  210. <p>
  211. <button class="js-programmatic-enable btn btn-primary">
  212. Enable
  213. </button>
  214. <button class="js-programmatic-disable btn btn-warning">
  215. Disable
  216. </button>
  217. </p>
  218. </div>
  219. <div class="col-md-8">
  220. <h2>Example code</h2>
  221. <pre data-fill-from=".js-code-disabled"></pre>
  222. <script type="text/javascript" class="js-code-disabled">
  223. $(".js-programmatic-enable").on("click", function () {
  224. $(".js-example-disabled").prop("disabled", false);
  225. $(".js-example-disabled-multi").prop("disabled", false);
  226. });
  227. $(".js-programmatic-disable").on("click", function () {
  228. $(".js-example-disabled").prop("disabled", true);
  229. $(".js-example-disabled-multi").prop("disabled", true);
  230. });
  231. </script>
  232. </div>
  233. </section>
  234. <section id="disabled-results" class="row">
  235. <div class="col-md-4">
  236. <h1>Disabled results</h1>
  237. <p>
  238. Select2 will correctly handled disabled results, both with data coming
  239. from a standard select (when the <code>disabled</code> attribute is set)
  240. and from remote sources, where the object has
  241. <code>disabled: true</code> set.
  242. </p>
  243. <p>
  244. <select class="js-example-disabled-results form-control">
  245. <option value="one">First</option>
  246. <option value="two" disabled="disabled">Second (disabled)</option>
  247. <option value="three">Third</option>
  248. </select>
  249. </p>
  250. </div>
  251. <div class="col-md-8">
  252. <h2>Example code</h2>
  253. <pre data-fill-from=".js-code-disabled-results"></pre>
  254. <script type="text/x-example-code" class="js-code-disabled-results">
  255. <select class="js-example-disabled-results">
  256. <option value="one">First</option>
  257. <option value="two" disabled="disabled">Second (disabled)</option>
  258. <option value="three">Third</option>
  259. </select>
  260. </script>
  261. </div>
  262. </section>
  263. <section id="tagss" class="row">
  264. <div class="col-md-4">
  265. <h1>Programmatic access</h1>
  266. <p>
  267. Select2 supports methods that allow programmatic control of the
  268. component.
  269. </p>
  270. <p>
  271. <button class="js-programmatic-set-val btn btn-primary">
  272. Set to California
  273. </button>
  274. <button class="js-programmatic-open btn btn-success">
  275. Open
  276. </button>
  277. <button class="js-programmatic-close btn btn-success">
  278. Close
  279. </button>
  280. <button class="js-programmatic-init btn btn-danger">
  281. Init
  282. </button>
  283. <button class="js-programmatic-destroy btn btn-danger">
  284. Destroy
  285. </button>
  286. </p>
  287. <p>
  288. <select class="js-example-programmatic js-states form-control"></select>
  289. </p>
  290. <p>
  291. <button class="js-programmatic-multi-set-val btn btn-primary">
  292. Set to California and Alabama
  293. </button>
  294. <button class="js-programmatic-multi-clear btn btn-primary">
  295. Clear
  296. </button>
  297. </p>
  298. <p>
  299. <select class="js-example-programmatic-multi js-states form-control" multiple="multiple"></select>
  300. </p>
  301. </div>
  302. <div class="col-md-8">
  303. <h2>Example code</h2>
  304. <pre data-fill-from=".js-code-programmatic"></pre>
  305. <script type="text/javascript" class="js-code-programmatic">
  306. var $example = $(".js-example-programmatic");
  307. var $exampleMulti = $(".js-example-programmatic-multi");
  308. $(".js-programmatic-set-val").on("click", function () { $example.val("CA").trigger("change"); });
  309. $(".js-programmatic-open").on("click", function () { $example.select2("open"); });
  310. $(".js-programmatic-close").on("click", function () { $example.select2("close"); });
  311. $(".js-programmatic-init").on("click", function () { $example.select2(); });
  312. $(".js-programmatic-destroy").on("click", function () { $example.select2("destroy"); });
  313. $(".js-programmatic-multi-set-val").on("click", function () { $exampleMulti.val(["CA", "AL"]).trigger("change"); });
  314. $(".js-programmatic-multi-clear").on("click", function () { $exampleMulti.val(null).trigger("change"); });
  315. </script>
  316. </div>
  317. </section>
  318. <section id="tags" class="row">
  319. <div class="col-md-4">
  320. <h1>Tagging support</h1>
  321. <p>
  322. Select2 can be used to quickly set up fields used for tagging.
  323. </p>
  324. <p>
  325. <select class="js-example-tags form-control">
  326. <option value="one">First</option>
  327. <option value="other">Other</option>
  328. </select>
  329. </p>
  330. <p>
  331. Note that when tagging is enabled the user can select from pre-existing
  332. options or create a new tag by picking the first choice, which is what
  333. the user has typed into the search box so far.
  334. </p>
  335. </div>
  336. <div class="col-md-8">
  337. <h2>Example code</h2>
  338. <pre data-fill-from=".js-code-tags"></pre>
  339. <script type="text/x-example-code" class="js-code-tags">
  340. $(".js-example-tags").select2({
  341. tags: true
  342. })
  343. </script>
  344. </div>
  345. </section>
  346. <section id="matcher" class="row">
  347. <div class="col-md-4">
  348. <h1>Custom matcher</h1>
  349. <p>
  350. Unlike other dropdowns on this page, this one matches options only if
  351. the term appears in the beginning of the string as opposed to anywhere:
  352. </p>
  353. <p>
  354. <select class="js-example-matcher-start js-states form-control"></select>
  355. </p>
  356. <p>
  357. This custom matcher uses a
  358. <a href="options.html#compat-matcher">compatibility module</a> that is
  359. only bundled in the
  360. <a href="index.html#versions">full version of Select2</a>. You also
  361. have the option of using a
  362. <a href="options.html#matcher">more complex matcher</a>.
  363. </p>
  364. </div>
  365. <div class="col-md-8">
  366. <h2>Example code</h2>
  367. <pre data-fill-from=".js-code-matcher-start"></pre>
  368. <script type="text/x-example-code" class="js-code-matcher-start">
  369. function matchStart (term, text) {
  370. if (text.toUpperCase().indexOf(term.toUpperCase()) == 0) {
  371. return true;
  372. }
  373. return false;
  374. }
  375. $.select2.amd.require(['select2/compat/matcher'], function (oldMatcher) {
  376. $(".js-example-matcher-start").select2({
  377. matcher: oldMatcher(matchStart)
  378. })
  379. });
  380. </script>
  381. </div>
  382. </section>
  383. <section id="diacritics" class="row">
  384. <div class="col-md-4">
  385. <h1>Diacritics support</h1>
  386. <p>
  387. Select2's default matcher will ignore diacritics, making it easier for
  388. users to filter results in international selects. Type "aero" into the
  389. select below.
  390. </p>
  391. <p>
  392. <select class="js-example-diacritics form-control">
  393. <option>Aeróbics</option>
  394. <option>Aeróbics en Agua</option>
  395. <option>Aerografía</option>
  396. <option>Aeromodelaje</option>
  397. <option>Águilas</option>
  398. <option>Ajedrez</option>
  399. <option>Ala Delta</option>
  400. <option>Álbumes de Música</option>
  401. <option>Alusivos</option>
  402. <option>Análisis de Escritura a Mano</option>
  403. </select>
  404. </p>
  405. </div>
  406. <div class="col-md-8">
  407. <h2>Example code</h2>
  408. <pre data-fill-from=".js-code-diacritics"></pre>
  409. <script type="text/x-example-code" class="js-code-diacritics">
  410. $(".js-example-diacritics").select2();
  411. </script>
  412. </div>
  413. </section>
  414. <section id="language" class="row">
  415. <div class="col-md-4">
  416. <h1>Multiple languages</h1>
  417. <p>
  418. Select2 supports displaying the messages in different languages, as well
  419. as provding your own
  420. <a href="options.html#language">custom messages</a>
  421. that can be displayed.
  422. </p>
  423. <p>
  424. <select class="js-example-language js-states form-control">
  425. </select>
  426. </p>
  427. <p>
  428. The language does not have to be defined when Select2 is being
  429. initialized, but instead can be defined in the <code>[lang]</code>
  430. attribute of any parent elements as <code>[lang="es"]</code>.
  431. </p>
  432. </div>
  433. <div class="col-md-8">
  434. <h2>Example code</h2>
  435. <pre data-fill-from=".js-code-language"></pre>
  436. <script type="text/x-example-code" class="js-code-language">
  437. $(".js-example-language").select2({
  438. language: "es"
  439. });
  440. </script>
  441. </div>
  442. </section>
  443. <section id="themes" class="row">
  444. <div class="col-md-4">
  445. <h1>Theme support</h1>
  446. <p>
  447. Select2 supports custom themes using the
  448. <a href="options.html#theme">theme option</a>
  449. so you can style Select2 to match the rest of your application.
  450. </p>
  451. <p>
  452. <select class="js-example-theme-single js-states form-control">
  453. </select>
  454. </p>
  455. <p>
  456. These are using the <code>classic</code> theme, which matches the old
  457. look of Select2.
  458. </p>
  459. <p>
  460. <select class="js-example-theme-multiple js-states form-control" multiple="multiple"></select>
  461. </p>
  462. </div>
  463. <div class="col-md-8">
  464. <h2>Example code</h2>
  465. <pre data-fill-from=".js-code-theme"></pre>
  466. <script type="text/x-example-code" class="js-code-theme">
  467. $(".js-example-theme-single").select2({
  468. theme: "classic"
  469. });
  470. $(".js-example-theme-multiple").select2({
  471. theme: "classic"
  472. });
  473. </script>
  474. </div>
  475. </section>
  476. </div>
  477. <select class="js-source-states" style="display: none;">
  478. <optgroup label="Alaskan/Hawaiian Time Zone">
  479. <option value="AK">Alaska</option>
  480. <option value="HI">Hawaii</option>
  481. </optgroup>
  482. <optgroup label="Pacific Time Zone">
  483. <option value="CA">California</option>
  484. <option value="NV">Nevada</option>
  485. <option value="OR">Oregon</option>
  486. <option value="WA">Washington</option>
  487. </optgroup>
  488. <optgroup label="Mountain Time Zone">
  489. <option value="AZ">Arizona</option>
  490. <option value="CO">Colorado</option>
  491. <option value="ID">Idaho</option>
  492. <option value="MT">Montana</option>
  493. <option value="NE">Nebraska</option>
  494. <option value="NM">New Mexico</option>
  495. <option value="ND">North Dakota</option>
  496. <option value="UT">Utah</option>
  497. <option value="WY">Wyoming</option>
  498. </optgroup>
  499. <optgroup label="Central Time Zone">
  500. <option value="AL">Alabama</option>
  501. <option value="AR">Arkansas</option>
  502. <option value="IL">Illinois</option>
  503. <option value="IA">Iowa</option>
  504. <option value="KS">Kansas</option>
  505. <option value="KY">Kentucky</option>
  506. <option value="LA">Louisiana</option>
  507. <option value="MN">Minnesota</option>
  508. <option value="MS">Mississippi</option>
  509. <option value="MO">Missouri</option>
  510. <option value="OK">Oklahoma</option>
  511. <option value="SD">South Dakota</option>
  512. <option value="TX">Texas</option>
  513. <option value="TN">Tennessee</option>
  514. <option value="WI">Wisconsin</option>
  515. </optgroup>
  516. <optgroup label="Eastern Time Zone">
  517. <option value="CT">Connecticut</option>
  518. <option value="DE">Delaware</option>
  519. <option value="FL">Florida</option>
  520. <option value="GA">Georgia</option>
  521. <option value="IN">Indiana</option>
  522. <option value="ME">Maine</option>
  523. <option value="MD">Maryland</option>
  524. <option value="MA">Massachusetts</option>
  525. <option value="MI">Michigan</option>
  526. <option value="NH">New Hampshire</option>
  527. <option value="NJ">New Jersey</option>
  528. <option value="NY">New York</option>
  529. <option value="NC">North Carolina</option>
  530. <option value="OH">Ohio</option>
  531. <option value="PA">Pennsylvania</option>
  532. <option value="RI">Rhode Island</option>
  533. <option value="SC">South Carolina</option>
  534. <option value="VT">Vermont</option>
  535. <option value="VA">Virginia</option>
  536. <option value="WV">West Virginia</option>
  537. </optgroup>
  538. </select>
  539. <script type="text/javascript">
  540. var $states = $(".js-source-states");
  541. var statesOptions = $states.html();
  542. $states.remove();
  543. $(".js-states").append(statesOptions);
  544. $("[data-fill-from]").each(function () {
  545. var $this = $(this);
  546. var codeContainer = $this.data("fill-from");
  547. var $container = $(codeContainer);
  548. var code = $.trim($container.html());
  549. $this.text(code);
  550. $this.addClass("prettyprint linenums");
  551. });
  552. prettyPrint();
  553. $.fn.select2.amd.require(
  554. ["select2/core", "select2/utils", "select2/compat/matcher"],
  555. function (Select2, Utils, oldMatcher) {
  556. var $basicSingle = $(".js-example-basic-single");
  557. var $basicMultiple = $(".js-example-basic-multiple");
  558. var $dataArray = $(".js-example-data-array");
  559. var $dataArraySelected = $(".js-example-data-array-selected");
  560. var data = [{ id: 0, text: 'enhancement' }, { id: 1, text: 'bug' }, { id: 2, text: 'duplicate' }, { id: 3, text: 'invalid' }, { id: 4, text: 'wontfix' }];
  561. var $ajax = $(".js-example-data-ajax");
  562. var $disabledResults = $(".js-example-disabled-results");
  563. var $tags = $(".js-example-tags");
  564. var $matcherStart = $('.js-example-matcher-start');
  565. var $diacritics = $(".js-example-diacritics");
  566. var $language = $(".js-example-language");
  567. $basicSingle.select2();
  568. $basicMultiple.select2()
  569. $dataArray.select2({
  570. data: data
  571. });
  572. $dataArraySelected.select2({
  573. data: data
  574. });
  575. $ajax.select2({
  576. ajax: {
  577. url: "https://api.github.com/search/repositories",
  578. dataType: 'json',
  579. delay: 250,
  580. data: function (params) {
  581. return {
  582. q: params.term, // search term
  583. page: params.page
  584. };
  585. },
  586. processResults: function (data, page) {
  587. // parse the results into the format expected by Select2.
  588. // since we are using custom formatting functions we do not need to
  589. // alter the remote JSON data
  590. return data.items;
  591. },
  592. cache: true
  593. },
  594. minimumInputLength: 1,
  595. templateResult: function (repo) {
  596. if (repo.loading) return repo.text;
  597. var markup = '<div class="clearfix">' +
  598. '<div class="col-sm-1">' +
  599. '<img src="' + repo.owner.avatar_url + '" style="max-width: 100%" />' +
  600. '</div>' +
  601. '<div clas="col-sm-10">' +
  602. '<div class="clearfix">' +
  603. '<div class="col-sm-6">' + repo.full_name + '</div>' +
  604. '<div class="col-sm-3"><i class="fa fa-code-fork"></i> ' + repo.forks_count + '</div>' +
  605. '<div class="col-sm-2"><i class="fa fa-star"></i> ' + repo.stargazers_count + '</div>' +
  606. '</div>';
  607. if (repo.description) {
  608. markup += '<div>' + repo.description + '</div>';
  609. }
  610. markup += '</div></div>';
  611. return markup;
  612. },
  613. templateSelection: function (repo) {
  614. return repo.full_name || repo.text;
  615. }
  616. });
  617. $(".js-example-disabled").select2();
  618. $(".js-example-disabled-multi").select2();
  619. $disabledResults.select2();
  620. $(".js-example-programmatic").select2();
  621. $(".js-example-programmatic-multi").select2();
  622. $tags.select2({
  623. tags: ['red', 'blue', 'green']
  624. });
  625. function matchStart (term, text) {
  626. if (text.toUpperCase().indexOf(term.toUpperCase()) == 0) {
  627. return true;
  628. }
  629. return false;
  630. }
  631. $matcherStart.select2({
  632. matcher: oldMatcher(matchStart)
  633. });
  634. $diacritics.select2();
  635. $language.select2({
  636. language: "es"
  637. });
  638. $(".js-example-theme-single").select2({
  639. theme: "classic"
  640. });
  641. $(".js-example-theme-multiple").select2({
  642. theme: "classic"
  643. });
  644. });
  645. </script>