@@ -40,8 +40,7 @@ <h1>Select2 4.0.0</h1>
4040 < em > will</ em > require you to read the release notes carefully, but the
4141 migration path should be relatively straightforward. You can find more
4242 information on the modules that have been created to make upgrading easier
43- by < a href ="compat.html "> looking at the compatibility guide</ a > for older
44- Select2 versions.
43+ by looking through < a href ="release-notes.html "> the release notes</ a > .
4544 </ p >
4645
4746 < p >
@@ -78,7 +77,7 @@ <h2>New features</h2>
7877 </ section >
7978
8079 < section id ="plugins ">
81- < h2 > Plugins </ h2 >
80+ < h2 > Plugin system </ h2 >
8281
8382 < p >
8483 Select2 now provides interfaces that allow for it to be easily extended,
@@ -88,38 +87,152 @@ <h2>Plugins</h2>
8887 Select2.
8988 </ p >
9089
91- < h3 >
92- Container (selection)
93- </ h3 >
90+ < p >
91+ The adapters implement a consistent interface that is documented in the
92+ < a href ="options.html#adapters "> options section for adapters</ a > , allowing
93+ you to customize Select2 to do exactly what you are looking for. Select2
94+ is designed such that you can mix and match plugins, with most of the core
95+ options being built as decorators that wrap the standard adapters.
96+ </ p >
97+ </ section >
98+
99+ < section id ="amd-builds ">
100+ < h2 > AMD-based build system</ h2 >
101+ </ section >
102+
103+ < section id ="migrating ">
104+ < h1 > Migrating from Select2 3.5</ h1 >
105+
106+ < p >
107+ There are a few breaking changes that migrators should be aware of when
108+ they are coming from older versions of Select2.
109+ </ p >
110+
111+ < h2 id ="hidden-input "> No more hidden input tags</ h2 >
94112
95113 < p >
96- This includes the primary container that users interact with to open the
97- dropdown.
114+ In past versions of Select2, an < code > <input type="hidden" /></ code >
115+ tag was recommended if you wanted to do anything advanced with Select2,
116+ such as work with remote data sources or allow users to add their own
117+ tags. This had the unfortunate side-effect of servers not receiving the
118+ data from Select2 as an array, like a standard < code > <select></ code >
119+ element does, but instead sending a string containing the comma-separated
120+ strings. The code base ended up being littered with special cases for the
121+ hidden input, and libraries using Select2 had to work around the
122+ differences it caused.
98123 </ p >
99124
100- < h3 >
101- Dropdown
102- </ h3 >
125+ < p >
126+ In Select2 4.0, the < code > <select></ code > element supports all core
127+ options, and support for the old
128+ < code > <input type="hidden" /></ code > has been removed. This means
129+ that if you previously declared an AJAX field with some pre-selected
130+ options that looked like...
131+ </ p >
132+
133+ < pre class ="prettyprint linenums ">
134+ <input type="hidden" name="select-boxes" value="1,2,4,6" />
135+ </ pre >
136+
137+ < p >
138+ Will need to be recreated as a < code > <select></ code > element with
139+ some < code > <option></ code > tags that have < code > value</ code >
140+ attributes that match the old value.
141+ </ p >
142+
143+ < pre class ="prettyprint linenums ">
144+ <select name="select-boxes" multiple="multiple">
145+ <option value="1" selected="selected">Select2</option>
146+ <option value="2" selected="selected">Chosen</option>
147+ <option value="4" selected="selected">selectize.js</option>
148+ <option value="6" selected="selected">typeahead.js</option>
149+ </select>
150+ </ pre >
151+
152+ < p >
153+ The options that you create should have < code > selected="selected"</ code >
154+ set, so Select2 and the browser knows that they should be selected. The
155+ < code > value</ code > attribute of the option should also be set to the value
156+ that will be returned from the server for the result, so Select2 can
157+ highlight it as selected in the dropdown. The text within the option
158+ should also reflect the value that should be displayed by default for the
159+ option.
160+ </ p >
161+
162+ < h2 id ="new-matcher "> Advanced matching of searches</ h2 >
163+
164+ < p >
165+ In past versions of Select2, when matching search terms to individual
166+ options, which limited the control that you had when displaying results,
167+ especially in cases where there was nested data. The < code > matcher</ code >
168+ function was only given the individual option, even if it was a nested
169+ options, without any context.
170+ </ p >
171+
172+ < p >
173+ With the new matcher function, only the root-level options are matched and
174+ matchers are expected to limit the results of any children options that
175+ they contain. This allows developers to customize how options within
176+ groups can be displayed, and modify how the results are returned.
177+ </ p >
178+
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.
183+ </ p >
184+
185+ < h2 id ="flexible-placeholders "> More flexible placeholders</ h2 >
186+
187+ < p >
188+ In the most recent versions of Select2, placeholders could only be
189+ applied to the first (typically the default) option in a
190+ < code > <select></ code > if it was blank. The
191+ < code > placeholderOption</ code > option was added to Select2 to allow users
192+ using the < code > select</ code > tag to select a different option, typically
193+ an automatically generated option with a different value.
194+ </ p >
195+
196+ < p >
197+ The < code > placeholder</ code > option can now take an object as well as just
198+ a string. This replaces the need for the old
199+ < code > placeholderOption</ code > , as now the < code > id</ code > of the object
200+ can be set to the < code > value</ code > attribute of the
201+ < code > <option></ code > tag.
202+ </ p >
103203
104204 < p >
105- This includes the dropdown that is opened when the container is clicked.
106- This also includes the results list, which is a separate component .
205+ For a select that looks like the following, where the first option (with a
206+ value of < code > -1 </ code > ) is the placeholder option.. .
107207 </ p >
108208
109- < h3 >
110- Results
111- </ h3 >
209+ < pre class ="prettyprint linenums ">
210+ <select>
211+ <option value="-1" selected="selected">Select an option</option>
212+ <option value="1">Something else</option>
213+ </select>
214+ </ pre >
112215
113216 < p >
114- This includes the list of possible options that can be selected.
217+ You would have previously had to get the placeholder option through the
218+ < code > placeholderOption</ code > , but now you can do it through the
219+ < code > placeholder</ code > option by setting an < code > id</ code > .
115220 </ p >
116221
117- < h3 >
118- Data set
119- </ h3 >
222+ < pre class ="prettyprint linenums ">
223+ $("select").select2({
224+ placeholder: {
225+ id: "-1",
226+ placeholder: "Select an option"
227+ }
228+ })
229+ </ pre >
120230
121231 < p >
122- This is how the options are calculated.
232+ And Select2 will automatically display the placeholder when the value of
233+ the select is < code > -1</ code > , which it is by default. This does not break
234+ the old functionality of Select2 where the placeholder option was blank by
235+ default.
123236 </ p >
124237 </ section >
125238</ div >
0 commit comments