options.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. ---
  2. layout: default
  3. title: Options - Select2
  4. slug: options
  5. ---
  6. <div class="container">
  7. <section id="core">
  8. <div class="page-header">
  9. <h1>Core options</h1>
  10. </div>
  11. <p>
  12. Select2 supports a small subset of options in every build that is
  13. generated. Each option typically has a decorator that is required that
  14. wraps an adapter, adding support for the option. This is only required
  15. when a custom adapter is being used, as Select2 will build the required
  16. adapters by default.
  17. </p>
  18. <p>
  19. Select2 will automatically apply decorators to any adapters which have not
  20. been manually overriden. The only time you need to decorate adapters is
  21. when you are using third-party adapters not provided by Select2, or you
  22. are using features not provided in the Select2 core. You can apply a
  23. decorator to an adapter using the
  24. <code title="select2/utils">Utils.Decorate</code> method provided with
  25. Select2.
  26. </p>
  27. <pre class="prettyprint linenums">
  28. $.fn.select2.amd.require(
  29. ["select2/utils", "select2/selection/single", "select2/selection/placeholder"],
  30. function (Utils, SingleSelection, Placeholder) {
  31. var CustomSelectionAdapter = Utils.Decorate(SingleSelection, Placeholder);
  32. });
  33. </pre>
  34. <p>
  35. All core options that use decorators or adapters will clearly state it
  36. in the "Decorator" or "Adapter" part of the documentation. Decorators are
  37. typically only compatible with a specific type of adapter, so make sure to
  38. note what adapter is given.
  39. </p>
  40. <h2 id="data-attributes">
  41. Declaring configuration in the <code>data-*</code> attributes
  42. </h2>
  43. <p>
  44. It is recommended that you declare your configuration options for Select2
  45. when initializing Select2. You can also define your configuration options
  46. by using the HTML5 <code>data-*</code> attributes, which will override
  47. any options set when initializing Select2 and any defaults.
  48. </p>
  49. <p>
  50. This means that if you declare your <code>&lt;select&gt;</code> tag as...
  51. </p>
  52. <pre class="prettyprint linenums">
  53. &lt;select data-tags="true" data-placeholder="Select an option"&gt;&lt;/select&gt;
  54. </pre>
  55. <p>
  56. Will be interpreted the same as initializing Select2 as...
  57. </p>
  58. <pre class="prettyprint linenums">
  59. $("select").select2({
  60. tags: "true",
  61. placeholder: "Select an option"
  62. });
  63. </pre>
  64. <p>
  65. You can also define nested configurations, which are typically needed for
  66. options such as AJAX. Each level of nesting should be separated by two
  67. dashes (<code>--</code>) instead of one.
  68. </p>
  69. <pre class="prettyprint linenums">
  70. &lt;select data-ajax--url="http://example.org/api/test" data-ajax--cache="true"&gt;&lt;/select&gt;
  71. </pre>
  72. <p>
  73. Which will be interpreted the same as initializing Select2 with...
  74. </p>
  75. <pre class="prettyprint linenums">
  76. $("select").select2({
  77. ajax: {
  78. url: "http://example.org/api/test",
  79. cache: "true"
  80. }
  81. });
  82. </pre>
  83. <p>
  84. The value of the option is subject to jQuery's
  85. <a href="https://api.jquery.com/data/#data-html5">parsing rules</a> for
  86. HTML5 data attributes.
  87. </p>
  88. <h2>
  89. Display
  90. </h2>
  91. <p>
  92. Select2 provides options that allow you to directly affect how the
  93. container that holds the current selection is displayed.
  94. </p>
  95. <h3 id="placeholder">
  96. Placeholders
  97. </h3>
  98. <p>
  99. Select2 can display a placeholder for a single-value select that will
  100. replace an option, or be shown when no options are selected for
  101. multiple-value selects. You can find an example on the
  102. <a href="examples.html#placeholders">example page</a>.
  103. </p>
  104. <div class="row">
  105. <div class="col-sm-4">
  106. <dl class="dl-horizontal">
  107. <dt>Key</dt>
  108. <dd>
  109. <code>placeholder</code>
  110. </dd>
  111. <dt>Value</dt>
  112. <dd>string or object</dd>
  113. </dl>
  114. <hr />
  115. <dl class="dl-horizontal">
  116. <dt>Adapter</dt>
  117. <dd>
  118. <code title="select2/selection/base">SelectionAdapter</code>
  119. </dd>
  120. <dt>Decorator</dt>
  121. <dd>
  122. <code title="select2/selection/placeholder">Placeholder</code>
  123. and
  124. <code title="select2/dropdown/hidePlaceholder">HidePlaceholder</code>
  125. </dd>
  126. </dl>
  127. </div>
  128. <div class="col-sm-8">
  129. <div class="alert alert-warning">
  130. <strong>Heads up!</strong>
  131. Because browsers assume that the first <code>option</code> in
  132. single-value select boxes is selected, you must add an empty
  133. <code>&lt;option&gt;&lt;/option&gt;</code> tag that the placeholder
  134. should use, or it will not work.
  135. </div>
  136. </div>
  137. </div>
  138. <p>
  139. If the <strong>value is a string</strong>, the placeholder will be
  140. displayed when a <strong>blank option</strong> is used as the placeholder.
  141. The <strong>value</strong> will be the message to show to users as the
  142. placeholders.
  143. </p>
  144. <pre class="prettyprint linenums">
  145. placeholder: "Select a repository",
  146. </pre>
  147. <p>
  148. If the <strong>value is an object</strong>, the object should be
  149. compatible with Select2's internal objects. The <code>id</code> should
  150. be the id to look for when determining if the placeholder should be
  151. displayed. The <code>text</code> should be the placeholder to display
  152. when that option is selected.
  153. </p>
  154. <pre class="prettyprint linenums">
  155. placeholder: {
  156. id: "-1",
  157. text: "Select a repository"
  158. }
  159. </pre>
  160. <div class="alert alert-info">
  161. You should <strong>pass in an object</strong> when you are using a
  162. framework that <strong>creates its own placeholder option</strong>. The
  163. <strong>id</strong> should be the same as the <code>value</code>
  164. attribute on the <code>option</code>.
  165. </div>
  166. <p id="allowClear">
  167. You can allow a selected option to be cleared back to the placeholder by
  168. enabling the <code>allowClear</code> option.
  169. </p>
  170. <div class="row">
  171. <div class="col-sm-6">
  172. <dl class="dl-horizontal">
  173. <dt>Key</dt>
  174. <dd><code>allowClear</code></dd>
  175. <dt>Value</dt>
  176. <dd>boolean</dd>
  177. </dl>
  178. </div>
  179. <div class="col-sm-6">
  180. <dl class="dl-horizontal">
  181. <dt>Adapter</dt>
  182. <dd>
  183. <code title="select2/selection/base">SelectionAdapter</code>
  184. </dd>
  185. <dt>Decorator</dt>
  186. <dd>
  187. <code title="select2/selection/allowClear">AllowClear</code>
  188. </dd>
  189. </dl>
  190. </div>
  191. </div>
  192. <p>
  193. This will display an "x" that the user can click to clear the current
  194. selection. It is designed to be used for cases where a single selection
  195. can be made.
  196. </p>
  197. <h3 id="multiple">
  198. Multiple selections
  199. </h3>
  200. <p>
  201. Select2 can display either a single selection or multiple selections.
  202. </p>
  203. <dl class="dl-horizontal">
  204. <dt>Key</dt>
  205. <dd><code>multiple</code></dd>
  206. <dt>Value</dt>
  207. <dd>boolean (<code>true</code> or <code>false</code>)</dd>
  208. </dl>
  209. This option will determine what the <code>SelectAdapter</code> (used by
  210. default) should use to set the value of the underlying <code>select</code>
  211. element. It will also determine if the <code>MultipleSelection</code>
  212. adapter should be used.
  213. <h3 id="language">
  214. Internationalization (Language support)
  215. </h3>
  216. <p>
  217. Messages will be displayed to users when necessary, such as when no
  218. search results were found or more characters need to be entered in order
  219. for a search to be made. These messages have been
  220. <a href="community.html#translations">translated into many languages</a>
  221. by contributors to Select2, but you can also provide your own
  222. translations.
  223. </p>
  224. <div class="row">
  225. <div class="col-sm-4">
  226. <dl class="dl-horizontal">
  227. <dt>Key</dt>
  228. <dd><code>language</code></dd>
  229. <dt>Value</dt>
  230. <dd>object or string</dd>
  231. </dl>
  232. <hr />
  233. <dl class="dl-horizontal">
  234. <dt>Module</dt>
  235. <dd>
  236. <code title="select2/translation">Translation</code>
  237. </dd>
  238. </dl>
  239. </div>
  240. <div class="col-sm-8">
  241. <p class="alert alert-warning">
  242. <strong>Heads up!</strong> When using translations provided by Select2,
  243. you must make sure to include the translation file in your page after
  244. Select2.
  245. </p>
  246. </div>
  247. </div>
  248. <p>
  249. When a string is passed in as the language, Select2 will try to resolve
  250. it into a language file. This allows you to specify your own language
  251. files, which must be defined as an AMD module. If the language file
  252. cannot be found, Select2 will assume it is a language code controlled by
  253. Select2, and it will try to load the translations for that language
  254. instead.
  255. </p>
  256. <p>
  257. You can include your own translations by providing an object similar to
  258. the one below.
  259. </p>
  260. <pre class="prettyprint">
  261. language: {
  262. // You can find all of the options in the language files provided in the
  263. // build. They all must be functions that return the string that should be
  264. // displayed.
  265. inputTooShort: function () {
  266. return "You must enter more characters...";
  267. }
  268. }
  269. </pre>
  270. <h2>
  271. Results
  272. </h2>
  273. <p>
  274. Select2 can work on many different data sets ranging from local options,
  275. the same way that a <code>&lt;select&gt;</code> typically works, from
  276. remote options where a server generates the results that users can select
  277. from.
  278. </p>
  279. <h3 id="data">
  280. Array
  281. </h3>
  282. <p>
  283. Select2 allows creating the results based on an array of data objects that
  284. is included when initializing Select2.
  285. </p>
  286. <div class="row">
  287. <div class="col-sm-6">
  288. <dl class="dl-horizontal">
  289. <dt>Key</dt>
  290. <dd><code>data</code></dd>
  291. <dt>Value</dt>
  292. <dd>array of objects</dd>
  293. </dl>
  294. </div>
  295. <div class="col-sm-6">
  296. <dl class="dl-horizontal">
  297. <dt>Adapter</dt>
  298. <dd>
  299. <code title="select2/data/array">ArrayAdapter</code>
  300. </dd>
  301. </dl>
  302. </div>
  303. </div>
  304. <p>
  305. The objects that the users can select from should be passed as an array
  306. with each object containing <code>id</code> and <code>text</code>
  307. properties.
  308. </p>
  309. <h3 id="ajax">
  310. AJAX
  311. </h3>
  312. <p>
  313. Select2 allows searching for results from remote data sources using AJAX
  314. requests.
  315. </p>
  316. <div class="row">
  317. <div class="col-sm-6">
  318. <dl class="dl-horizontal">
  319. <dt>Key</dt>
  320. <dd><code>ajax</code></dd>
  321. <dt>Value</dt>
  322. <dd>object</dd>
  323. </dl>
  324. </div>
  325. <div class="col-sm-6">
  326. <dl class="dl-horizontal">
  327. <dt>Adapter</dt>
  328. <dd>
  329. <code title="select2/data/ajax">AjaxAdapter</code>
  330. </dd>
  331. </dl>
  332. </div>
  333. </div>
  334. <p>
  335. All options passed to this option will be directly passed to the
  336. <code>$.ajax</code> function that executes AJAX requests. There are a few
  337. custom options that Select2 will intercept, allowing you to customize the
  338. request as it is being made.
  339. <pre class="prettyprint">
  340. ajax: {
  341. // The number of milliseconds to wait for the user to stop typing before
  342. // issuing the ajax request.
  343. delay: 250,
  344. // You can craft a custom url based on the parameters that are passed into the
  345. // request. This is useful if you are using a framework which has
  346. // JavaScript-based functions for generating the urls to make requests to.
  347. //
  348. // @param params The object containing the parameters used to generate the
  349. // request.
  350. // @returns The url that the request should be made to.
  351. url: function (params) {
  352. return UrlGenerator.Random();
  353. },
  354. // You can pass custom data into the request based on the parameters used to
  355. // make the request. For `GET` requests, the default method, these are the
  356. // query parameters that are appended to the url. For `POST` requests, this
  357. // is the form data that will be passed into the request. For other requests,
  358. // the data returned from here should be customized based on what jQuery and
  359. // your server are expecting.
  360. //
  361. // @param params The object containing the parameters used to generate the
  362. // request.
  363. // @returns Data to be directly passed into the request.
  364. data: function (params) {
  365. var queryParameters = {
  366. q: params.term
  367. }
  368. return queryParameters;
  369. },
  370. // You can modify the results that are returned from the server, allowing you
  371. // to make last-minute changes to the data, or find the correct part of the
  372. // response to pass to Select2. Keep in mind that results should be passed as
  373. // an array of objects.
  374. //
  375. // @param data The data as it is returned directly by jQuery.
  376. // @returns An array of objects that will be rendered by Select2.
  377. processResults: function (data) {
  378. return data;
  379. }
  380. }
  381. </pre>
  382. </p>
  383. <h3 id="tags">
  384. Tags
  385. </h3>
  386. <p>
  387. Users can create their own options based on the text that they have
  388. entered.
  389. </p>
  390. <div class="row">
  391. <div class="col-sm-6">
  392. <dl class="dl-horizontal">
  393. <dt>Key</dt>
  394. <dd><code>tags</code></dd>
  395. <dt>Value</dt>
  396. <dd>boolean / array of objects</dd>
  397. </dl>
  398. </div>
  399. <div class="col-sm-6">
  400. <dl class="dl-horizontal">
  401. <dt>Adapter</dt>
  402. <dd>
  403. <code title="select2/data/base">DataAdapter</code>
  404. </dd>
  405. <dt>Decorator</dt>
  406. <dd>
  407. <code title="select2/data/tags">Tags</code>
  408. </dd>
  409. </dl>
  410. </div>
  411. </div>
  412. <p>
  413. If the <code>tags</code> option is passed into Select2, if a user types
  414. anything into the search box which doesn't already exist, it will be
  415. displayed at the top and the user will be able to select it.
  416. </p>
  417. <p>
  418. <strong>For backwards compatibility</strong>, if an array of objects is
  419. passed in with the <code>tags</code> option, the options will be
  420. automatically created and the user will be able to select from them.
  421. This is the <strong>same as how <a href="#data">array data</a>
  422. works</strong>, and has similar limitations.
  423. </p>
  424. </section>
  425. <section id="dropdown">
  426. <div class="page-header">
  427. <h1>Dropdown</h1>
  428. </div>
  429. <p>
  430. Select2 allows you to change the way that the dropdown works, allowing you
  431. to do anything from attach it to a different location in the document or
  432. add a search box.
  433. </p>
  434. <h2 id="dropdownParent">
  435. Attached to body
  436. </h2>
  437. <p>
  438. By default, Select2 will attach the dropdown to the end of the body and
  439. will absolutely position it to appear below the selection container.
  440. </p>
  441. <div class="row">
  442. <div class="col-sm-4">
  443. <dl class="dl-horizontal">
  444. <dt>Key</dt>
  445. <dd><code>dropdownParent</code></dd>
  446. <dt>Value</dt>
  447. <dd>jQuery element or DOM node</dd>
  448. <hr />
  449. <dt>Adapter</dt>
  450. <dd>
  451. <code title="select2/dropdown">DropdownAdapter</code>
  452. </dd>
  453. <dt>Decorator</dt>
  454. <dd>
  455. <code title="select2/dropdown/attachBody">AttachBody</code>
  456. </dd>
  457. </dl>
  458. </div>
  459. <div class="col-sm-8">
  460. <div class="alert alert-warning">
  461. <strong>Heads up!</strong>
  462. This will cause DOM events to be raised outside of the standard
  463. Select2 DOM container. This can cause issues with
  464. third-party components such as modals.
  465. </div>
  466. </div>
  467. </div>
  468. <p>
  469. When the dropdown is attached to the body, you are not limited to just
  470. displaying the dropdown below the container. Select2 will display above
  471. the container if there is not enough space below the container, but there
  472. is enough space above it. You are also not limited to displaying the
  473. drodown within the parent container, which means Select2 will render
  474. correctly inside of modals and other small containers.
  475. </p>
  476. <h2 id="dropdown-attachContainer">
  477. Attached below the container
  478. </h2>
  479. <p>
  480. Select2 can place the dropdown directly after the selection cotainer, so
  481. it will appear in the same location within the DOM as the rest of Select2.
  482. </p>
  483. <dl class="dl-horizontal">
  484. <dt>Adapter</dt>
  485. <dd>
  486. <code title="select2/dropdown">DropdownAdapter</code>
  487. </dd>
  488. <dt>Decorator</dt>
  489. <dd>
  490. <code title="select2/dropdown/attachContainer">AttachContainer</code>
  491. </dd>
  492. </dl>
  493. <div class="alert alert-info">
  494. <strong>
  495. <a href="https://harvesthq.github.io/chosen/">Harvest Chosen</a>
  496. migrators!
  497. </strong>
  498. If you are migrating to Select2 from Chosen, this option will cause
  499. Select2 to position the dropdown in a similar way.
  500. </div>
  501. <h2 id="dropdown-search">
  502. Search
  503. </h2>
  504. <p>
  505. Users can filter down the results by typing a search term into a box that
  506. is displayed at the top of the dropdown.
  507. </p>
  508. <dl class="dl-horizontal">
  509. <dt>Adapter</dt>
  510. <dd>
  511. <code title="select2/dropdown">DropdownAdapter</code>
  512. </dd>
  513. <dt>Decorator</dt>
  514. <dd>
  515. <code title="select2/dropdown/search">DropdownSearch</code>
  516. </dd>
  517. </dl>
  518. <p>
  519. A search box is added to the top of the dropdown automatically for select
  520. boxes where only a single option can be selected.
  521. </p>
  522. </section>
  523. <section id="adapters">
  524. <div class="page-header">
  525. <h1>Adapters</h1>
  526. </div>
  527. <p>
  528. Select2 allows plugins to add additional functionality through the core
  529. adapters. You can change almost anything involving the way Select2 works
  530. to the way Select2 interacts with the page by modifying the core adapters.
  531. Most third-party plugins should provide decorators (used to wrap adapters)
  532. and custom adpaters that you can use.
  533. </p>
  534. <p>
  535. Each adapter contains a set of methods which will must always be defined.
  536. Along with the global methods that all adapters must implement, these
  537. methods must be implemented.
  538. </p>
  539. <h2>
  540. All adapters
  541. </h2>
  542. <p>
  543. All adapters must implement a set of methods that Select2 will use to
  544. display them and bind any internal events.
  545. </p>
  546. <pre class="prettyprint linenums">
  547. // The basic HTML that should be rendered by Select2. A jQuery or DOM element
  548. // should be returned, which will automatically be placed by Select2 within the
  549. // DOM.
  550. //
  551. // @returns A jQuery or DOM element that contains any elements that must be
  552. // rendered by Select2.
  553. Adapter.render = function () {
  554. return $jq;
  555. };
  556. // Bind to any Select2 or DOM events.
  557. //
  558. // @param container The Select2 object that is bound to the jQuery element. You
  559. // can listen to Select2 events with `on` and trigger Select2 events using the
  560. // `trigger` method.
  561. // @param $container The jQuery DOM node that all default adapters will be
  562. // rendered within.
  563. Adapter.bind = function (container, $container) { };
  564. // Position the DOM element within the Select2 DOM container, or in another
  565. // place. This allows adapters to be located outside of the Select2 DOM,
  566. // such as at the end of the document or in a specific place within the Select2
  567. // DOM node.
  568. //
  569. // Note: This method is not called on data adapters.
  570. //
  571. // @param $rendered The rendered DOM element that was returned from the call to
  572. // `render`. This may have been modified by Select2, but the root element
  573. // will always be the same.
  574. // @param $defaultContainer The default container that Select2 will typically
  575. // place the rendered DOM element within. For most adapters, this is the
  576. // Select2 DOM element.
  577. Adapter.position = function ($rendered, $defaultContainer) { };
  578. // Destroy any events or DOM elements that have been created.
  579. // This is called when `select2("destroy")` is called on an element.
  580. Adapter.destroy = function () { };
  581. </pre>
  582. <h2 id="selectionAdapter">
  583. Container (selection)
  584. </h2>
  585. <p>
  586. The selection is what is shown to the user as a replacement of the
  587. standard <code>&lt;select&gt;</code> box. It controls the display of the
  588. selection option(s), as well anything else that needs to be embedded
  589. within the container, such as a search box.
  590. </p>
  591. <dl class="dl-horizontal">
  592. <dt>Key</dt>
  593. <dd>
  594. <code>selectionAdapter</code>
  595. </dd>
  596. <dt>Default</dt>
  597. <dd>
  598. <code title="select2/selection/single">SingleSelection</code> or
  599. <code title="select2/selection/multiple">MultipleSelection</code>
  600. </dd>
  601. <dt>Base</dt>
  602. <dd>
  603. <code title="select2/selection/base">BaseSelection</code>
  604. </dd>
  605. </dl>
  606. <pre class="prettyprint linenums">
  607. // Update the selected data.
  608. //
  609. // @param data An array of data objects that have been generated by the data
  610. // adapter. If no objects should be selected, an empty array will be passed.
  611. //
  612. // Note: An array will always be passed into this method, even if Select2 is
  613. // attached to a source which only accepts a single selection.
  614. SelectionAdapter.update = function (data) { };
  615. </pre>
  616. <h2 id="dataAdapter">
  617. Data set
  618. </h2>
  619. <p>
  620. The data set is what Select2 uses to generate the possible results that
  621. can be selected, as well as the currently selected results.
  622. </p>
  623. <dl class="dl-horizontal">
  624. <dt>Key</dt>
  625. <dd>
  626. <code>dataAdapter</code>
  627. </dd>
  628. <dt>Default</dt>
  629. <dd>
  630. <code title="select2/data/select">SelectAdapter</code>
  631. </dd>
  632. <dt>Base</dt>
  633. <dd>
  634. <code title="select2/data/base">BaseAdapter</code>
  635. </dd>
  636. </dl>
  637. <pre class="prettyprint linenums">
  638. // Get the currently selected options. This is called when trying to get the
  639. // initial selection for Select2, as well as when Select2 needs to determine
  640. // what options within the results are selected.
  641. //
  642. // @param callback A function that should be called when the current selection
  643. // has been retrieved. The first paramter to the function should be an array
  644. // of data objects.
  645. DataAdapter.current = function (callback) {
  646. callback(currentData);
  647. }
  648. // Get a set of options that are filtered based on the parameters that have
  649. // been passed on in.
  650. //
  651. // @param params An object containing any number of parameters that the query
  652. // could be affected by. Only the core parameters will be documented.
  653. // @param params.term A user-supplied term. This is typically the value of the
  654. // search box, if one exists, but can also be an empty string or null value.
  655. // @param params.page The specific page that should be loaded. This is typically
  656. // provided when working with remote data sets, which rely on pagination to
  657. // determine what objects should be displayed.
  658. // @param callback The function that should be called with the queried results.
  659. DataAdapter.query = function (params, callback) {
  660. callback(queryiedData);
  661. }
  662. </pre>
  663. <h2 id="dropdownAdapter">
  664. Dropdown
  665. </h2>
  666. <p>
  667. The dropdown adapter defines the main container that the dropdown should
  668. be held in. <strong>It does not define any extra methods that can be used
  669. for decorators</strong>, but it is common for decorators to attach to the
  670. <code>render</code> and <code>position</code> methods to alter how the
  671. dropdown is altered and positioned.
  672. </p>
  673. <dl class="dl-horizontal">
  674. <dt>Key</dt>
  675. <dd>
  676. <code>dropdownAdapter</code>
  677. </dd>
  678. <dt>Default</dt>
  679. <dd>
  680. <code title="select2/dropdown">DropdownAdapter</code>
  681. </dd>
  682. </dl>
  683. <h2 id="resultsAdapter">
  684. Results
  685. </h2>
  686. <p>
  687. The results adapter controls the list of results that the user can select
  688. from. While the results adapter does not define any additional methods
  689. that must be implemented, it makes extensive use of the Select2 event
  690. system for cotrolling the display of results and messages.
  691. </p>
  692. <dl class="dl-horizontal">
  693. <dt>Key</dt>
  694. <dd>
  695. <code>resultsAdapter</code>
  696. </dd>
  697. <dt>Default</dt>
  698. <dd>
  699. <code title="select2/results">ResultsAdapter</code>
  700. </dd>
  701. </dl>
  702. </section>
  703. </div>
  704. <script type="text/javascript">
  705. prettyPrint();
  706. </script>