55---
66
77< div class ="container ">
8- < section id ="pre-release ">
9- < h1 > Pre-release notes</ h1 >
10-
11- < hr />
12-
13- < p class ="lead ">
14- The 4.0 release is ready for early adopters interested in testing it out.
15- You can use the development version, available on GitHub, by getting the
16- source code available in the < code > select2-ng</ code > branch. The source
17- code can be
18- < a href ="https://github.com/select2/select2/archive/select2-ng.zip ">
19- downloaded as a < code > zip</ code > archive
20- </ a > as well.
21- </ p >
22- </ section >
23-
24- < hr />
25-
268 < section id ="release ">
279 < h1 > Select2 4.0.0</ h1 >
2810
@@ -157,7 +139,7 @@ <h2 id="hidden-input">No more hidden input tags</h2>
157139 < p >
158140 In Select2 4.0, the < code > <select></ code > element supports all core
159141 options, and support for the old
160- < code > <input type="hidden" /></ code > has been removed . This means
142+ < code > <input type="hidden" /></ code > has been deprecated . This means
161143 that if you previously declared an AJAX field with some pre-selected
162144 options that looked like...
163145 </ p >
@@ -167,7 +149,7 @@ <h2 id="hidden-input">No more hidden input tags</h2>
167149</ pre >
168150
169151 < p >
170- Will need to be recreated as a < code > <select></ code > element with
152+ It will need to be recreated as a < code > <select></ code > element with
171153 some < code > <option></ code > tags that have < code > value</ code >
172154 attributes that match the old value.
173155 </ p >
@@ -215,6 +197,57 @@ <h2 id="new-matcher">Advanced matching of searches</h2>
215197 matcher function.
216198 </ p >
217199
200+ < p >
201+ So if your old code used a matcher that only displayed options if they
202+ started with the term that was entered, it would look something like...
203+ </ p >
204+
205+ < pre class ="prettyprint linenums ">
206+ function matchStart (term, text) {
207+ if (text.toUpperCase().indexOf(term.toUpperCase()) == 0) {
208+ return true;
209+ }
210+
211+ return false;
212+ }
213+
214+ $("select").select2({
215+ matcher: matchStart
216+ })
217+ </ pre >
218+
219+ < p >
220+ Then in Select2 4.0, you would need to wrap the < code > matchStart</ code >
221+ method (or the name of the matcher you created) with a
222+ < code > oldMatcher</ code > method that we have created.
223+ </ p >
224+
225+ < pre class ="prettyprint linenums ">
226+ function matchStart (term, text) {
227+ if (text.toUpperCase().indexOf(term.toUpperCase()) == 0) {
228+ return true;
229+ }
230+
231+ return false;
232+ }
233+
234+ $.fn.select2.amd.require(['select2/compat/matcher'], function (oldMatcher) {
235+ $("select").select2({
236+ matcher: oldMatcher(matchStart)
237+ })
238+ });
239+ </ pre >
240+
241+ < p >
242+ This will work for any matchers that only took in the search term and the
243+ text of the option as parameters. If your matcher relied on the third
244+ parameter containing the jQuery element representing the original
245+ < code > <option></ code > tag, then you may need to slightly change
246+ your matcher to expect the full JavaScript data object being passed in
247+ instead. You can still retrieve the jQuery element from the data object
248+ using the < code > data.element</ code > property.
249+ </ p >
250+
218251 < h2 id ="flexible-placeholders "> More flexible placeholders</ h2 >
219252
220253 < p >
@@ -263,9 +296,9 @@ <h2 id="flexible-placeholders">More flexible placeholders</h2>
263296
264297 < p >
265298 And Select2 will automatically display the placeholder when the value of
266- the select is < code > -1</ code > , which it is by default. This does not break
267- the old functionality of Select2 where the placeholder option was blank by
268- default.
299+ the select is < code > -1</ code > , which it will be by default. This does not
300+ break the old functionality of Select2 where the placeholder option was
301+ blank by default.
269302 </ p >
270303
271304 < h2 id ="value-ordering "> Display reflects the actual order of the values</ h2 >
0 commit comments