announcements-4.0.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. ---
  2. layout: default
  3. title: Select2 4.0.0 Released
  4. slug: announcements-4.0
  5. ---
  6. <div class="container">
  7. <section id="pre-release">
  8. <h1>Pre-release notes</h1>
  9. <hr />
  10. <p class="lead">
  11. The 4.0 release is ready for early adopters interested in testing it out.
  12. You can use the development version, available on GitHub, by getting the
  13. source code available in the <code>select2-ng</code> branch. The source
  14. code can be
  15. <a href="https://github.com/select2/select2/archive/select2-ng.zip">
  16. downloaded as a <code>zip</code> archive
  17. </a> as well.
  18. </p>
  19. </section>
  20. <hr />
  21. <section id="release">
  22. <h1>Select2 4.0.0</h1>
  23. <p>
  24. The 4.0 release of Select2 is the result of three years of working on the
  25. code base and watching where it needs to go. At the core, it is a full
  26. rewrite that addresses many of the extensibility and usability problems
  27. that could not be addressed in previous versions.
  28. </p>
  29. <p>
  30. This release contains many breaking changes, but easy-upgrade paths have
  31. been created as well as helper modules that will allow for backwards
  32. compatibility to be maintained with past versions of Select2. Upgrading
  33. <em>will</em> require you to read the release notes carefully, but the
  34. migration path should be relatively straightforward. You can view a list
  35. of the most common changes that you will need to make
  36. <a href="https://github.com/select2/select2/releases">in the release notes</a>.
  37. </p>
  38. <p>
  39. Below is an in-depth review of what is new in Select2, as well as some of
  40. the major changes that have been made.
  41. </p>
  42. </section>
  43. <section id="new">
  44. <h2>New features</h2>
  45. <p>
  46. The notable features of this new release include:
  47. </p>
  48. <ul>
  49. <li>
  50. A more flexible plugin framework that allows you to override Select2 to
  51. behave exactly how you want it to.
  52. </li>
  53. <li>
  54. Consistency with standard <code>&lt;select&gt;</code> elements for all
  55. data adapters, removing the need for hidden <code>&lt;input&gt;</code>
  56. elements.
  57. </li>
  58. <li>
  59. A new build system that uses AMD to keep everything organized.
  60. </li>
  61. <li>
  62. Less specific selectors allowing for Select2 to be styled to fit the
  63. rest of your application.
  64. </li>
  65. </ul>
  66. </section>
  67. <section id="plugins">
  68. <h2>Plugin system</h2>
  69. <p>
  70. Select2 now provides interfaces that allow for it to be easily extended,
  71. allowing for anyone to create a plugin that changes the way Select2 works.
  72. This is the result of Select2 being broken into four distinct sections,
  73. each of which can be extended and used together to create your unique
  74. Select2.
  75. </p>
  76. <p>
  77. The adapters implement a consistent interface that is documented in the
  78. <a href="options.html#adapters">options section for adapters</a>, allowing
  79. you to customize Select2 to do exactly what you are looking for. Select2
  80. is designed such that you can mix and match plugins, with most of the core
  81. options being built as decorators that wrap the standard adapters.
  82. </p>
  83. </section>
  84. <section id="amd-builds">
  85. <h2>AMD-based build system</h2>
  86. <p>
  87. Select2 now uses an
  88. <a href="https://en.wikipedia.org/wiki/Asynchronous_module_definition">AMD-based build system</a>,
  89. allowing for builds that only require the parts of Select2 that you need.
  90. While a custom build system has not yet been created, Select2 is open
  91. source and will gladly accept a pull request for one.
  92. </p>
  93. <p>
  94. Select2 includes the minimal <a href="https://github.com/jrburke/almond">almond</a>
  95. AMD loader, but a custom <code>select2.amd.js</code> build is available
  96. if you already use an AMD loader. The code base (available in the
  97. <code>src</code> directory) also uses AMD, allowing you to include Select2
  98. in your own build system and generate your own builds alongside your
  99. existing infrastructure.
  100. </p>
  101. <p>
  102. The AMD methods used by Select2 are available as
  103. <code>jQuery.fn.select2.amd.define()/require()</code>, allowing you to use the
  104. included almond loader. These methods are primarily used by the
  105. translations, but they are the recommended way to access custom modules
  106. that Select2 provides.
  107. </p>
  108. </section>
  109. <section id="migrating">
  110. <h1>Migrating from Select2 3.5</h1>
  111. <p>
  112. There are a few breaking changes that migrators should be aware of when
  113. they are coming from older versions of Select2.
  114. </p>
  115. <p>
  116. If you use the full build of Select2 (<code>select2.full.js</code>), you
  117. will be automatically notified of the major breaking changes, and
  118. compatibility modules will be used in some cases to ensure that your code
  119. still behaves how you were expecting.
  120. </p>
  121. <h2 id="hidden-input">No more hidden input tags</h2>
  122. <p>
  123. In past versions of Select2, an <code>&lt;input type="hidden" /&gt;</code>
  124. tag was recommended if you wanted to do anything advanced with Select2,
  125. such as work with remote data sources or allow users to add their own
  126. tags. This had the unfortunate side-effect of servers not receiving the
  127. data from Select2 as an array, like a standard <code>&lt;select&gt;</code>
  128. element does, but instead sending a string containing the comma-separated
  129. strings. The code base ended up being littered with special cases for the
  130. hidden input, and libraries using Select2 had to work around the
  131. differences it caused.
  132. </p>
  133. <p>
  134. In Select2 4.0, the <code>&lt;select&gt;</code> element supports all core
  135. options, and support for the old
  136. <code>&lt;input type="hidden" /&gt;</code> has been removed. This means
  137. that if you previously declared an AJAX field with some pre-selected
  138. options that looked like...
  139. </p>
  140. <pre class="prettyprint linenums">
  141. &lt;input type="hidden" name="select-boxes" value="1,2,4,6" /&gt;
  142. </pre>
  143. <p>
  144. Will need to be recreated as a <code>&lt;select&gt;</code> element with
  145. some <code>&lt;option&gt;</code> tags that have <code>value</code>
  146. attributes that match the old value.
  147. </p>
  148. <pre class="prettyprint linenums">
  149. &lt;select name="select-boxes" multiple="multiple"&gt;
  150. &lt;option value="1" selected="selected"&gt;Select2&lt;/option&gt;
  151. &lt;option value="2" selected="selected"&gt;Chosen&lt;/option&gt;
  152. &lt;option value="4" selected="selected"&gt;selectize.js&lt;/option&gt;
  153. &lt;option value="6" selected="selected"&gt;typeahead.js&lt;/option&gt;
  154. &lt;/select&gt;
  155. </pre>
  156. <p>
  157. The options that you create should have <code>selected="selected"</code>
  158. set so Select2 and the browser knows that they should be selected. The
  159. <code>value</code> attribute of the option should also be set to the value
  160. that will be returned from the server for the result, so Select2 can
  161. highlight it as selected in the dropdown. The text within the option
  162. should also reflect the value that should be displayed by default for the
  163. option.
  164. </p>
  165. <h2 id="new-matcher">Advanced matching of searches</h2>
  166. <p>
  167. In past versions of Select2, when matching search terms to individual
  168. options, which limited the control that you had when displaying results,
  169. especially in cases where there was nested data. The <code>matcher</code>
  170. function was only given the individual option, even if it was a nested
  171. options, without any context.
  172. </p>
  173. <p>
  174. With the new matcher function, only the root-level options are matched and
  175. matchers are expected to limit the results of any children options that
  176. they contain. This allows developers to customize how options within
  177. groups can be displayed, and modify how the results are returned.
  178. </p>
  179. <p>
  180. A function has been created that allows old-style matcher functions to be
  181. converted to the new style. You can retrieve the function from the
  182. <code>select2/compat/matcher</code> module, which should just wrap the old
  183. matcher function.
  184. </p>
  185. <h2 id="flexible-placeholders">More flexible placeholders</h2>
  186. <p>
  187. In the most recent versions of Select2, placeholders could only be
  188. applied to the first (typically the default) option in a
  189. <code>&lt;select&gt;</code> if it was blank. The
  190. <code>placeholderOption</code> option was added to Select2 to allow users
  191. using the <code>select</code> tag to select a different option, typically
  192. an automatically generated option with a different value.
  193. </p>
  194. <p>
  195. The <code>placeholder</code> option can now take an object as well as just
  196. a string. This replaces the need for the old
  197. <code>placeholderOption</code>, as now the <code>id</code> of the object
  198. can be set to the <code>value</code> attribute of the
  199. <code>&lt;option&gt;</code> tag.
  200. </p>
  201. <p>
  202. For a select that looks like the following, where the first option (with a
  203. value of <code>-1</code>) is the placeholder option...
  204. </p>
  205. <pre class="prettyprint linenums">
  206. &lt;select&gt;
  207. &lt;option value="-1" selected="selected"&gt;Select an option&lt;/option&gt;
  208. &lt;option value="1"&gt;Something else&lt;/option&gt;
  209. &lt;/select&gt;
  210. </pre>
  211. <p>
  212. You would have previously had to get the placeholder option through the
  213. <code>placeholderOption</code>, but now you can do it through the
  214. <code>placeholder</code> option by setting an <code>id</code>.
  215. </p>
  216. <pre class="prettyprint linenums">
  217. $("select").select2({
  218. placeholder: {
  219. id: "-1",
  220. placeholder: "Select an option"
  221. }
  222. })
  223. </pre>
  224. <p>
  225. And Select2 will automatically display the placeholder when the value of
  226. the select is <code>-1</code>, which it is by default. This does not break
  227. the old functionality of Select2 where the placeholder option was blank by
  228. default.
  229. </p>
  230. <h2 id="value-ordering">Display reflects the actual order of the values</h2>
  231. <p>
  232. In past versions of Select2, choices were displayed in the order that
  233. they were selected. In cases where Select2 was used on a
  234. <code>&lt;select&gt;</code> element, the order that the server received
  235. the selections did not always match the order that the choices were
  236. displayed, resulting in confusion in situations where the order is
  237. important.
  238. </p>
  239. <p>
  240. Select2 will now order selected choices in the same order that will be
  241. sent to the server.
  242. </p>
  243. <h2 id="changed-options">Changed method and option names</h2>
  244. <p>
  245. When designing the future option set for Select2 4.0, special care was
  246. taken to ensure that the most commonly used options were brought over.
  247. For the most part, the commonly used options of Select2 can still be
  248. referenced under their previous names, but there were some changes which
  249. have been noted.
  250. </p>
  251. <h3 id="removed-initselection">
  252. Removed the requirement of <code>initSelection</code>
  253. </h3>
  254. <p>
  255. In the past, whenever you wanted to use a custom data adapter, such as
  256. AJAX or tagging, you needed to help Select2 out in determining the initial
  257. values that were selected. This was typically done through the
  258. <code>initSelection</code> option, which took the underlying data of the
  259. input and converted it into data objects that Select2 could use.
  260. </p>
  261. <p>
  262. This is now handled by
  263. <a href="options.html#dataAdapter">the data adapter</a> in the
  264. <code>current</code> method, which allows Select2 to convert the currently
  265. selected values into data objects that can be displayed. The default
  266. implementation converts the text and value of <code>option</code> elements
  267. into data objects, and is probably suitable for most cases. An example of
  268. the old <code>initSelection</code> option is included below, which
  269. converts the value of the selected options into a data object with both
  270. the <code>id</code> and <code>text</code> matching the selected value.
  271. </p>
  272. <pre class="prettyprint linenums">
  273. initSelection : function (element, callback) {
  274. var data = [];
  275. $(element.val()).each(function () {
  276. data.push({id: this, text: this});
  277. });
  278. callback(data);
  279. }
  280. </pre>
  281. <p>
  282. When using the new <code>current</code> method of the custom data adapter,
  283. <strong>this method is called any time Select2 needs a list</strong> of
  284. the currently selected options. This is different from the old
  285. <code>initSelection</code> in that it was only called once, so it could
  286. suffer from being relatively slow to process the data (such as from a
  287. remote data source).
  288. </p>
  289. <pre class="prettyprint linenums">
  290. $.fn.select2.amd.require(
  291. ['select2/data/array', 'select2/utils'],
  292. function (ArrayData, Utils) {
  293. function CustomData ($element, options) {
  294. CustomData.__super__.constructor.call(this, $element, options);
  295. }
  296. Utils.Extend(CustomData, ArrayData);
  297. CustomData.prototype.current = function (callback) {
  298. var data = [];
  299. var currentVal = this.$element.val();
  300. if (!this.$element.prop('multiple')) {
  301. currentVal = [currentVal];
  302. }
  303. for (var v = 0; v < currentVal.length; v++) {
  304. data.push({
  305. id: currentVal[v],
  306. text: currentVal[v]
  307. });
  308. }
  309. callback(data);
  310. };
  311. $("#select").select2({
  312. dataAdapter: CustomData
  313. });
  314. }
  315. </pre>
  316. <p>
  317. The new <code>current</code> method of the data adapter works in a similar
  318. way to the old <code>initSelection</code> method, with three notable
  319. differences. The first, and most important, is that <strong>it is called
  320. whenever the current selections are needed</strong> to ensure that Select2
  321. is always displaying the most accurate and up to date data. No matter
  322. what type of element Select2 is attached to, whether it supports a
  323. single or multiple selections, the data passed to the callback
  324. <strong>must be an array, even if it contains one selection</strong>.
  325. The last is that there is only one parameter, the callback to be
  326. executed with the latest data, and the current element that Select2 is
  327. attached to is available on the class itself as
  328. <code>this.$element</code>.
  329. </p>
  330. <p>
  331. If you only need to load in the initial options once, and otherwise will
  332. be letting Select2 handle the state of the selections, you don't need to
  333. use a custom data adapter. You can just create the
  334. <code>&lt;option&gt;</code> tags on your own, and Select2 will pick up
  335. the changes.
  336. </p>
  337. <pre class="prettyprint linenums">
  338. var $element = $('select').select2(); // the select element you are working with
  339. var $request = $.ajax({
  340. url: '/my/remote/source' // wherever your data is actually coming from
  341. });
  342. $request.then(function (data) {
  343. // This assumes that the data comes back as an array of data objects
  344. // The idea is that you are using the same callback as the old `initSelection`
  345. for (var d = 0; d < data.length; d++) {
  346. var item = data[d];
  347. // Create the DOM option that is pre-selected by default
  348. var option = new Option(data.text, data.id, true, true);
  349. // Append it to the select
  350. $element.append(option);
  351. }
  352. // Update the selected options that are displayed
  353. $element.trigger('change');
  354. });
  355. </pre>
  356. <h3 id="query-to-data-adapter">
  357. Custom data adapters instead of <code>query</code>
  358. </h3>
  359. <p>
  360. <a href="http://select2.github.io/select2/#data">In the past</a>, any time
  361. you wanted to hook Select2 up to a different data source you would be
  362. required to implement custom <code>query</code> and
  363. <code>initSelection</code> methods. This allowed Select2 to determine the
  364. initial selection and the list of results to display, and it would handle
  365. everything else internally, which was fine more most people.
  366. </p>
  367. <p>
  368. The custom <code>query</code> and <code>initSelection</code> methods have
  369. been replaced by
  370. <a href="options.html#dataAdapter">custom data adapters</a> that handle
  371. how Select2 stores and retrieves the data that will be displayed to the
  372. user. An example of the old <code>query</code> option is provided below,
  373. which is
  374. <a href="http://select2.github.io/select2/#data">the same as the old example</a>,
  375. and it generates results that contain the search term repeated a certain
  376. number of times.
  377. </p>
  378. <pre class="prettyprint linenums">
  379. query: function (query) {
  380. var data = {results: []}, i, j, s;
  381. for (i = 1; i < 5; i++) {
  382. s = "";
  383. for (j = 0; j < i; j++) {s = s + query.term;}
  384. data.results.push({id: query.term + i, text: s});
  385. }
  386. query.callback(data);
  387. }
  388. </pre>
  389. <p>
  390. This has been replaced by custom data adapters which define a similarly
  391. named <code>query</code> method. The comparable data adapter is provided
  392. below as an example.
  393. </p>
  394. <pre class="prettyprint linenums">
  395. $.fn.select2.amd.require(
  396. ['select2/data/array', 'select2/utils'],
  397. function (ArrayData, Utils) {
  398. function CustomData ($element, options) {
  399. CustomData.__super__.constructor.call(this, $element, options);
  400. }
  401. Utils.Extend(CustomData, ArrayData);
  402. CustomData.prototype.query = function (params, callback) {
  403. var data = {
  404. results: []
  405. };
  406. for (var i = 1; i < 5; i++) {
  407. var s = "";
  408. for (var j = 0; j < i; j++) {
  409. s = s + params.term;
  410. }
  411. data.results.push({
  412. id: params.term + i,
  413. text: s
  414. });
  415. }
  416. callback(data);
  417. };
  418. $("#select").select2({
  419. dataAdapter: CustomData
  420. });
  421. }
  422. </pre>
  423. <p>
  424. The new <code>query</code> method of the data adapter is very similar to
  425. the old <code>query</code> option that was passed into Select2 when
  426. initializing it. The old <code>query</code> argument is mostly the same as
  427. the new <code>params</code> that are passed in to query on, and the
  428. callback that should be used to return the results is now passed in as the
  429. second parameter.
  430. </p>
  431. <h3 id="changed-templating">Renamed templating options</h3>
  432. <p>
  433. Select2 previously provided multiple options for formatting the results
  434. list and selected options, commonly referred to as "formatters", using the
  435. <code>formatSelection</code> and <code>formatResult</code> options. As the
  436. "formatters" were also used for things such as localization,
  437. <a href="#changed-translations">which has also changed</a>, they have been
  438. renamed to <code>templateSelection</code> and <code>templateResult</code>
  439. and their signatures have changed as well.
  440. </p>
  441. <p>
  442. You should refer to the updated
  443. <a href="options.html#templating">documentation on templates</a> when
  444. migrating from previous versions of Select2.
  445. </p>
  446. <h3 id="changed-id">
  447. The <code>id</code> and <code>text</code> properties are strictly enforced
  448. </h3>
  449. <p>
  450. When working with array and AJAX data in the past, Select2 allowed a
  451. custom <code>id</code> function or attribute to be set in various places,
  452. ranging from the initialization of Select2 to when the remote data was
  453. being returned. This allowed Select2 to better integrate with existing
  454. data sources that did not necessarily use the <code>id</code> attribute to
  455. indicate the unique identifier for an object.
  456. </p>
  457. <p>
  458. Select2 no longer supports a custom <code>id</code> or <code>text</code>
  459. to be used, but provides integration points for converting incorrect data
  460. to the expected format.
  461. </p>
  462. <h4>
  463. When working with array data
  464. </h4>
  465. <p>
  466. Select2 previously supported defining array data as an object that matched
  467. the signature of an AJAX response. A <code>text</code> property could be
  468. specified that would map the given property to the <code>text</code>
  469. property on the individual objects. You can now do this when initializing
  470. Select2 by using the following jQuery code to map the old
  471. <code>text</code> and <code>id</code> properties to the new ones.
  472. </p>
  473. <pre class="prettyprint linenums">
  474. var data = $.map([
  475. {
  476. pk: 1,
  477. word: 'one'
  478. },
  479. {
  480. pk: 2,
  481. word: 'two'
  482. }
  483. ], function (obj) {
  484. obj.id = obj.id || obj.pk;
  485. obj.text = obj.text || obj.word;
  486. return obj;
  487. });
  488. </pre>
  489. <p>
  490. This will result in an array of data objects that have the <code>id</code>
  491. properties that match the existing <code>pk</code> properties and
  492. <code>text</code> properties that match the existing <code>word</code>
  493. properties.
  494. </p>
  495. <h4>
  496. When working with remote data
  497. </h4>
  498. <p>
  499. The same code that was given above can be used in the
  500. <code>processResults</code> method of an AJAX call to map properties there
  501. as well.
  502. </p>
  503. <h3 id="changed-translations">Renamed translation options</h3>
  504. <p>
  505. In previous versions of Select2, the default messages provided to users
  506. could be localized to fit the language of the website that it was being
  507. used on. Select2 only comes with the English language by default, but
  508. provides
  509. <a href="options.html#language">community-contributed translations</a> for
  510. many common languages. Many of the formatters have been moved to the
  511. <code>language</code> option and the signatures of the formatters have
  512. been changed to handle future additions.
  513. </p>
  514. <h3 id="changed-data">
  515. Declaring options using <code>data-*</code> attributes
  516. </h3>
  517. <p>
  518. In the past, Select2 has only supported declaring a subset of options
  519. using <code>data-*</code> attributes. Select2 now supports declaring all
  520. options using the attributes, using
  521. <a href="options.html#data-attributes">the format specified in the documentation</a>.
  522. </p>
  523. <p>
  524. You could previously declare the URL that was used for AJAX requests using
  525. the <code>data-ajax-url</code> attribute. While Select2 still allows for
  526. this, the new attribute that should be used is the
  527. <code>data-ajax--url</code> attribute. Support for the old attribute will
  528. be removed in Select2 4.1.
  529. </p>
  530. <p>
  531. Although it was not documented, a list of possible tags could also be
  532. provided using the <code>data-select2-tags</code> attribute and passing in
  533. a JSON-formatted array of objects for tags. As the method for specifying
  534. tags has changed in 4.0, you should now provide the array of objects using
  535. the <code>data-data</code> attribute, which maps to
  536. <a href="options.html#data">the array data</a> option. You should also
  537. enable tags by setting <code>data-tags="true"</code> on the object, to
  538. maintain the ability for users to create their own options as well.
  539. </p>
  540. <p>
  541. If you previously declared the list of tags as...
  542. </p>
  543. <pre class="prettyprint linenums">
  544. &lt;select data-select2-tags="[{id: '1', text: 'One', id: '2', text: 'Two'}]"&gt;&lt;/select&gt;
  545. </pre>
  546. <p>
  547. ...then you should now delare it as...
  548. </p>
  549. <pre class="prettyprint linenums">
  550. &lt;select data-data="[{id: '1', text: 'One', id: '2', text: 'Two'}]" data-tags="true"&gt;&lt;/select&gt;
  551. </pre>
  552. <h2 id="removed-methods">Deprecated and removed methods</h2>
  553. <p>
  554. As Select2 now uses a <code>&lt;select&gt;</code> element for all data
  555. sources, a few methods that were available by calling
  556. <code>.select2()</code> are no longer required.
  557. </p>
  558. <h3>.select2("val")</h3>
  559. <p>
  560. The <code>"val"</code> method has been deprecated and will be removed in
  561. Select2 4.1. The deprecated method no longer includes the
  562. <code>triggerChange</code> parameter.
  563. </p>
  564. <p>
  565. You should directly call <code>.val</code> on the underlying
  566. <code>&lt;select&gt;</code> element instead. If you needed the second
  567. parameter (<code>triggerChange</code>), you should also call
  568. <code>.trigger("change")</code> on the element.
  569. </p>
  570. <pre class="prettyprint linenums">
  571. $("select").val("1").trigger("change"); // instead of $("select").select2("val", "1");
  572. </pre>
  573. <h3>.select2("enable")</h3>
  574. <p>
  575. Select2 will respect the <code>disabled</code> property of the underlying
  576. select element. In order to enable or disable Select2, you should call
  577. <code>.prop('disabled', true/false)</code> on the
  578. <code>&lt;select&gt;</code> element. Support for the old methods will be
  579. completely removed in Select2 4.1.
  580. </p>
  581. <pre class="prettyprint linenums">
  582. $("select").prop("disabled", true); // instead of $("select").enable(false);
  583. </pre>
  584. </section>
  585. </div>
  586. <script type="text/javascript">
  587. prettyPrint();
  588. </script>