You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Select2 previously provided multiple options for formatting the results list and selected options, commonly referred to as "formatters", using the <code>formatSelection</code> and <code>formatResult</code> options. As the "formatters" were also used for things such as localization, <ahref="#changed-translations">which has also changed</a>, they have been renamed to <code>templateSelection</code> and <code>templateResult</code> and their signatures have changed as well.
293
+
Select2 previously provided multiple options for formatting the results
294
+
list and selected options, commonly referred to as "formatters", using the
295
+
<code>formatSelection</code> and <code>formatResult</code> options. As the
296
+
"formatters" were also used for things such as localization,
297
+
<ahref="#changed-translations">which has also changed</a>, they have been
298
+
renamed to <code>templateSelection</code> and <code>templateResult</code>
299
+
and their signatures have changed as well.
294
300
</p>
295
301
296
302
<p>
297
-
You should refer to the updated <ahref="options.html#templates">documentation on templates</a> when migrating from previous versions of Select2.
303
+
You should refer to the updated
304
+
<ahref="options.html#templates">documentation on templates</a> when
305
+
migrating from previous versions of Select2.
306
+
</p>
307
+
308
+
<h3id="changed-id">
309
+
The <code>id</code> and <code>text</code> properties are strictly enforced
310
+
</h3>
311
+
312
+
<p>
313
+
When working with array and AJAX data in the past, Select2 allowed a
314
+
custom <code>id</code> function or attribute to be set in various places,
315
+
ranging from the initializion of Select2 to when the remote data was being
316
+
returned. This allowed Select2 to better integrate with existing data
317
+
sources that did not necessarily use the <code>id</code> attribute to
318
+
indicate the unique identifier for an object.
319
+
</p>
320
+
321
+
<p>
322
+
Select2 no longer supports a custom <code>id</code> or <code>text</code>
323
+
to be used, but provides integration points for converting incorrect data
324
+
to the expected format.
325
+
</p>
326
+
327
+
<h4>
328
+
When working with array data
329
+
</h4>
330
+
331
+
<p>
332
+
Select2 previously supported defining array data as an object that matched
333
+
the signature of an AJAX response. A <code>text</code> property could be
334
+
specified that would map the given property to the <code>text</code>
335
+
property on the individual objects. You can now do this when initializing
336
+
Select2 by using the following jQuery code to map the old
337
+
<code>text</code> and <code>id</code> properties to the new ones.
338
+
</p>
339
+
340
+
<preclass="prettyprint linenums">
341
+
var data = $.map([
342
+
{
343
+
pk: 1,
344
+
word: 'one'
345
+
},
346
+
{
347
+
pk: 2,
348
+
word: 'two'
349
+
}
350
+
], function (obj) {
351
+
obj.id = obj.id || obj.pk;
352
+
obj.text = obj.text || obj.word;
353
+
354
+
return obj;
355
+
});
356
+
</pre>
357
+
358
+
<p>
359
+
This will result in an array of data objects that have the <code>id</code>
360
+
properties that match the existing <code>pk</code> properties and
361
+
<code>text</code> properties that match the existing <code>word</code>
362
+
properties.
363
+
</p>
364
+
365
+
<h4>
366
+
When working with remote data
367
+
</h4>
368
+
369
+
<p>
370
+
The same code that was given above can be used in the
371
+
<code>processResults</code> method of an AJAX call to map properties there
In previous versions of Select2, the default messages provided to users could be localized to fit the language of the website that it was being used on. Select2 only comes with the English language by default, but provides <ahref="options.html#language">community-contributed translations</a> for many common languages. Many of the formatters have been moved to the <code>language</code> option and the signatures of the formatters have been changed to handle future additions.
378
+
In previous versions of Select2, the default messages provided to users
379
+
could be localized to fit the language of the website that it was being
380
+
used on. Select2 only comes with the English language by default, but
381
+
provides
382
+
<ahref="options.html#language">community-contributed translations</a> for
383
+
many common languages. Many of the formatters have been moved to the
384
+
<code>language</code> option and the signatures of the formatters have
385
+
been changed to handle future additions.
304
386
</p>
305
387
306
388
<h3id="changed-data">
@@ -323,7 +405,14 @@ <h3 id="changed-data">
323
405
</p>
324
406
325
407
<p>
326
-
Although it was not documented, a list of possible tags could also be provided using the <code>data-select2-tags</code> attribute and passing in a JSON-formatted array of objects for tags. As the method for specifying tags has changed in 4.0, you should now provide the array of objects using the <code>data-data</code> attribute, which maps to <ahref="options.html#data">the array data</a> option. You should also enable tags by setting <code>data-tags="true"</code> on the object, to maintain the ability for users to create their own options as well.
408
+
Although it was not documented, a list of possible tags could also be
409
+
provided using the <code>data-select2-tags</code> attribute and passing in
410
+
a JSON-formatted array of objects for tags. As the method for specifying
411
+
tags has changed in 4.0, you should now provide the array of objects using
412
+
the <code>data-data</code> attribute, which maps to
413
+
<ahref="options.html#data">the array data</a> option. You should also
414
+
enable tags by setting <code>data-tags="true"</code> on the object, to
415
+
maintain the ability for users to create their own options as well.
327
416
</p>
328
417
329
418
<p>
@@ -353,18 +442,22 @@ <h2 id="removed-methods">Deprecated and removed methods</h2>
353
442
<h3>.select2("val")</h3>
354
443
355
444
<p>
356
-
The <code>val</code> method has been deprecated and will be removed in
445
+
The <code>"val"</code> method has been deprecated and will be removed in
357
446
Select2 4.1. The deprecated method no longer includes the
358
447
<code>triggerChange</code> parameter.
359
448
</p>
360
449
361
450
<p>
362
-
You should directly call <code>val</code> on the underlying
451
+
You should directly call <code>.val</code> on the underlying
363
452
<code><select></code> element instead. If you needed the second
364
453
parameter (<code>triggerChange</code>), you should also call
365
454
<code>.trigger("change")</code> on the element.
366
455
</p>
367
456
457
+
<preclass="prettyprint linenums">
458
+
$("select").val("1"); // instead of $("select").select2("val", "1");
459
+
</pre>
460
+
368
461
<h3>.select2("enable")</h3>
369
462
370
463
<p>
@@ -374,6 +467,10 @@ <h3>.select2("enable")</h3>
374
467
<code><select></code> element. Support for the old methods will be
375
468
completely removed in Select2 4.1.
376
469
</p>
470
+
471
+
<preclass="prettyprint linenums">
472
+
$("select").prop("disabled", true); // instead of $("select").enable(false);
0 commit comments