backwards-compatibility.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. ### Compatibility module for Select2 v3.5
  2. This custom matcher uses a [compatibility module](/configuration/deprecated) that is only bundled in the [full version of Select2](/getting-started/builds). You also have the option of using a <a href="options.html#matcher">more complex matcher</a>.
  3. <div class="s2-example">
  4. <select class="js-example-matcher-compat js-states form-control"></select>
  5. </div>
  6. <pre data-fill-from=".js-code-example-matcher-compat"></pre>
  7. <script type="text/javascript" class="js-code-example-matcher-compat">
  8. function matchStart (term, text) {
  9. if (text.toUpperCase().indexOf(term.toUpperCase()) == 0) {
  10. return true;
  11. }
  12. return false;
  13. }
  14. $.fn.select2.amd.require(['select2/compat/matcher'], function (oldMatcher) {
  15. $(".js-example-matcher-compat").select2({
  16. matcher: oldMatcher(matchStart)
  17. })
  18. });
  19. </script>
  20. <section>
  21. <div class="page-header">
  22. <h1 id="compatibility">Backwards compatibility</h1>
  23. </div>
  24. <p>
  25. Select2 offers limited backwards compatibility with the previously 3.5.x
  26. release line, allowing people more efficiently transfer across releases
  27. and get the latest features. For many of the larger changes, such as the
  28. change in how custom data adapters work, compatibility modules were
  29. created that will be used to assist in the upgrade process. It is not
  30. recommended to rely on these compatibility modules, as they will not
  31. always exist, but they make upgrading easier for major changes.
  32. </p>
  33. <p>
  34. <strong>The compatibility modules are only included in the
  35. <a href="index.html#builds-full" class="alert-link">full builds</a> of
  36. Select2</strong>. These files end in <code>.full.js</code>, and the
  37. compatibility modules are prefixed with <code>select2/compat</code>.
  38. </p>
  39. <h2 id="compat-matcher">
  40. Simplified function for matching data objects
  41. </h2>
  42. <p class="alert alert-info">
  43. <a href="announcements-4.0.html#new-matcher" class="alert-link">Added in Select2 4.0.0.</a>
  44. This method was added to make upgrading easier from earlier versions of
  45. Select2.
  46. </p>
  47. <p>
  48. During the <a href="announcements-4.0.html">Select2 4.0.0 release</a>, the
  49. <code>matcher</code> function was changed to allow for more complex
  50. matching of nested objects.
  51. </p>
  52. <div class="row">
  53. <div class="col-sm-6">
  54. <dl class="dl-horizontal">
  55. <dt>Key</dt>
  56. <dd>
  57. <code>matcher</code>
  58. </dd>
  59. <dt>Value</dt>
  60. <dd>
  61. A function taking a search <code>term</code> and the data object
  62. <code>text</code>.
  63. </dd>
  64. </dl>
  65. </div>
  66. <div class="col-sm-6">
  67. <dl class="dl-horizontal">
  68. <dt>Adapter</dt>
  69. <dd>
  70. <code title="select2/compat/matcher">oldMatcher</code>
  71. </dd>
  72. </dl>
  73. </div>
  74. </div>
  75. <p>
  76. The <a href="examples.html#matcher">custom matcher example</a> provides a
  77. guide for how to use this in your own application. For those upgrading
  78. from older versions of Select2, you just need to wrap your old
  79. <code>matcher</code> with this function to maintain compatibility.
  80. </p>
  81. <h2 id="initSelection">
  82. Old initial selections with <code>initSelection</code>
  83. </h2>
  84. <p class="alert alert-warning">
  85. <a href="announcements-4.0.html#removed-initselection" class="alert-link">Deprecated in Select2 4.0.</a>
  86. This has been replaced by another option and is only available in the
  87. <a href="index.html#builds-full" class="alert-link">full builds</a> of
  88. Select2.
  89. </p>
  90. <p>
  91. In the past, Select2 required an option called <code>initSelection</code>
  92. that was defined whenever a custom data source was being used, allowing
  93. for the initial selection for the component to be determined. This has
  94. been replaced by the <code>current</code> method on the
  95. <a href="#dataAdapter">data adapter</a>.
  96. </p>
  97. <div class="row">
  98. <div class="col-sm-6">
  99. <dl class="dl-horizontal">
  100. <dt>Key</dt>
  101. <dd>
  102. <code>initSelection</code>
  103. </dd>
  104. <dt>Value</dt>
  105. <dd>
  106. A function taking a <code>callback</code>
  107. </dd>
  108. </dl>
  109. </div>
  110. <div class="col-sm-6">
  111. <dl class="dl-horizontal">
  112. <dt>Adapter</dt>
  113. <dd>
  114. <code title="select2/data/base">DataAdapter</code>
  115. </dd>
  116. <dt>Decorator</dt>
  117. <dd>
  118. <code title="select2/compat/initSelection">InitSelection</code>
  119. </dd>
  120. </dl>
  121. </div>
  122. </div>
  123. <h2 id="query">
  124. Querying old data with <code>query</code>
  125. </h2>
  126. <p class="alert alert-warning">
  127. <a href="announcements-4.0.html#query-to-data-adapter" class="alert-link">Deprecated in Select2 4.0.</a>
  128. This has been replaced by another option and is only available in the
  129. <a href="index.html#builds-full" class="alert-link">full builds</a> of
  130. Select2.
  131. </p>
  132. <p>
  133. In the past, Select2 supported an option called <code>query</code> that
  134. allowed for a custom data source to be used. This option has been replaced
  135. by the <code>query</code> method on the
  136. <a href="#dataAdapter">data adapter</a> and takes a very similar set of
  137. parameters.
  138. </p>
  139. <div class="row">
  140. <div class="col-sm-6">
  141. <dl class="dl-horizontal">
  142. <dt>Key</dt>
  143. <dd>
  144. <code>query</code>
  145. </dd>
  146. <dt>Value</dt>
  147. <dd>
  148. A function taking <code>params</code> (including a <code>callback</code>)
  149. </dd>
  150. </dl>
  151. </div>
  152. <div class="col-sm-6">
  153. <dl class="dl-horizontal">
  154. <dt>Adapter</dt>
  155. <dd>
  156. <code title="select2/data/base">DataAdapter</code>
  157. </dd>
  158. <dt>Decorator</dt>
  159. <dd>
  160. <code title="select2/compat/query">Query</code>
  161. </dd>
  162. </dl>
  163. </div>
  164. </div>
  165. <h2 id="input-fallback">
  166. Compatibility with <code>&lt;input type="text" /&gt;</code>
  167. </h2>
  168. <p class="alert alert-warning">
  169. <a href="announcements-4.0.html#hidden-input" class="alert-link">Deprecated in Select2 4.0.</a>
  170. It is now encouraged to use the <code>&lt;select&gt;</code> tag instead.
  171. </p>
  172. <p>
  173. In past versions of Select2, a <code>&lt;select&gt;</code> element could
  174. only be used with a limited subset of options. An
  175. <code>&lt;input type="hidden" /&gt;</code> was required instead, which did
  176. not allow for a graceful fallback for users who did not have JavaScript
  177. enabled. Select2 now supports the <code>&lt;select&gt;</code> element for
  178. all options, so it is no longer required to use <code>&lt;input /&gt;</code>
  179. elements with Select2.
  180. </p>
  181. <dl class="dl-horizontal">
  182. <dt>Adapter</dt>
  183. <dd>
  184. <code title="select2/data/base">DataAdapter</code>
  185. </dd>
  186. <dt>Decorator</dt>
  187. <dd>
  188. <code title="select2/compat/inputData">InputData</code>
  189. </dd>
  190. </dl>
  191. </section>