backwards-compatibility.html 5.9 KB

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