Skip to content

Commit df40e22

Browse files
committed
Finish off the initial release notes and prepare for beta
1 parent 05cbaf7 commit df40e22

3 files changed

Lines changed: 119 additions & 13 deletions

File tree

docs/_includes/navigation.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
<span class="caret"></span>
2828
</a>
2929
<ul class="dropdown-menu">
30+
<li>
31+
<a href="https://github.com/select2/select2/releases">
32+
Release notes
33+
</a>
34+
</li>
3035
<li{% if page.slug == "announcements-4.0" %} class="active"{% endif %}>
3136
<a href="./announcements-4.0.html">4.0 Announcement</a>
3237
</li>

docs/announcements-4.0.html

Lines changed: 106 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ <h1>Select2 4.0.0</h1>
3838
been created as well as helper modules that will allow for backwards
3939
compatibility to be maintained with past versions of Select2. Upgrading
4040
<em>will</em> require you to read the release notes carefully, but the
41-
migration path should be relatively straightforward. You can find more
42-
information on the modules that have been created to make upgrading easier
43-
by looking through <a href="release-notes.html">the release notes</a>.
41+
migration path should be relatively straightforward. You can view a list
42+
of the most common changes that you will need to make
43+
<a href="https://github.com/select2/select2/releases">in the release notes</a>.
4444
</p>
4545

4646
<p>
@@ -290,17 +290,99 @@ <h2 id="changed-options">Changed method and option names</h2>
290290
<h3 id="changed-templating">Renamed templating options</h3>
291291

292292
<p>
293-
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, <a href="#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+
<a href="#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.
294300
</p>
295301

296302
<p>
297-
You should refer to the updated <a href="options.html#templates">documentation on templates</a> when migrating from previous versions of Select2.
303+
You should refer to the updated
304+
<a href="options.html#templates">documentation on templates</a> when
305+
migrating from previous versions of Select2.
306+
</p>
307+
308+
<h3 id="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+
<pre class="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
372+
as well.
298373
</p>
299374

300375
<h3 id="changed-translations">Renamed translation options</h3>
301376

302377
<p>
303-
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 <a href="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+
<a href="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.
304386
</p>
305387

306388
<h3 id="changed-data">
@@ -323,7 +405,14 @@ <h3 id="changed-data">
323405
</p>
324406

325407
<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 <a href="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+
<a href="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.
327416
</p>
328417

329418
<p>
@@ -353,18 +442,22 @@ <h2 id="removed-methods">Deprecated and removed methods</h2>
353442
<h3>.select2("val")</h3>
354443

355444
<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
357446
Select2 4.1. The deprecated method no longer includes the
358447
<code>triggerChange</code> parameter.
359448
</p>
360449

361450
<p>
362-
You should directly call <code>val</code> on the underlying
451+
You should directly call <code>.val</code> on the underlying
363452
<code>&lt;select&gt;</code> element instead. If you needed the second
364453
parameter (<code>triggerChange</code>), you should also call
365454
<code>.trigger("change")</code> on the element.
366455
</p>
367456

457+
<pre class="prettyprint linenums">
458+
$("select").val("1"); // instead of $("select").select2("val", "1");
459+
</pre>
460+
368461
<h3>.select2("enable")</h3>
369462

370463
<p>
@@ -374,6 +467,10 @@ <h3>.select2("enable")</h3>
374467
<code>&lt;select&gt;</code> element. Support for the old methods will be
375468
completely removed in Select2 4.1.
376469
</p>
470+
471+
<pre class="prettyprint linenums">
472+
$("select").prop("disabled", true); // instead of $("select").enable(false);
473+
</pre>
377474
</section>
378475
</div>
379476

docs/options.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ <h3 id="placeholder">
155155
<div class="alert alert-warning">
156156
<strong>Heads up!</strong>
157157
Because browsers assume that the first <code>option</code> in
158-
single-value select boxes is selected, you must add an empty
158+
single-value select boxes is selected, you should add an empty
159159
<code>&lt;option&gt;&lt;/option&gt;</code> tag that the placeholder
160-
should use, or it will not work.
160+
should use or it may not work.
161161
</div>
162162
</div>
163163
</div>
@@ -441,9 +441,13 @@ <h3 id="ajax">
441441
// an array of objects.
442442
//
443443
// @param data The data as it is returned directly by jQuery.
444-
// @returns An array of objects that will be rendered by Select2.
444+
// @returns An object containing the results data as well as any required
445+
// metadata that is used by plugins. The object should contain an array of
446+
// data objects as the `results` key.
445447
processResults: function (data) {
446-
return data;
448+
return {
449+
results: data
450+
};
447451
}
448452
}
449453
</pre>

0 commit comments

Comments
 (0)