From 86bf6dc272c3f5aac4942f2c938104d51e2dd378 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Sun, 26 Apr 2015 16:27:22 -0400 Subject: [PATCH] Removed pre-release note This removes the pre-release note from the 4.0.0 announcement and also adds an example for the `matcher` option. --- docs/announcements-4.0.html | 79 ++++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/docs/announcements-4.0.html b/docs/announcements-4.0.html index 5e107c57..8076ae7b 100644 --- a/docs/announcements-4.0.html +++ b/docs/announcements-4.0.html @@ -5,24 +5,6 @@ slug: announcements-4.0 ---
-
-

Pre-release notes

- -
- -

- The 4.0 release is ready for early adopters interested in testing it out. - You can use the development version, available on GitHub, by getting the - source code available in the select2-ng branch. The source - code can be - - downloaded as a zip archive - as well. -

-
- -
-

Select2 4.0.0

@@ -157,7 +139,7 @@ slug: announcements-4.0

In Select2 4.0, the <select> element supports all core options, and support for the old - <input type="hidden" /> has been removed. This means + <input type="hidden" /> has been deprecated. This means that if you previously declared an AJAX field with some pre-selected options that looked like...

@@ -167,7 +149,7 @@ slug: announcements-4.0

- Will need to be recreated as a <select> element with + It will need to be recreated as a <select> element with some <option> tags that have value attributes that match the old value.

@@ -215,6 +197,57 @@ slug: announcements-4.0 matcher function.

+

+ So if your old code used a matcher that only displayed options if they + started with the term that was entered, it would look something like... +

+ +
+function matchStart (term, text) {
+  if (text.toUpperCase().indexOf(term.toUpperCase()) == 0) {
+    return true;
+  }
+
+  return false;
+}
+
+$("select").select2({
+  matcher: matchStart
+})
+
+ +

+ Then in Select2 4.0, you would need to wrap the matchStart + method (or the name of the matcher you created) with a + oldMatcher method that we have created. +

+ +
+function matchStart (term, text) {
+  if (text.toUpperCase().indexOf(term.toUpperCase()) == 0) {
+    return true;
+  }
+
+  return false;
+}
+
+$.fn.select2.amd.require(['select2/compat/matcher'], function (oldMatcher) {
+  $("select").select2({
+    matcher: oldMatcher(matchStart)
+  })
+});
+
+ +

+ This will work for any matchers that only took in the search term and the + text of the option as parameters. If your matcher relied on the third + parameter containing the jQuery element representing the original + <option> tag, then you may need to slightly change + your matcher to expect the full JavaScript data object being passed in + instead. You can still retrieve the jQuery element from the data object + using the data.element property. +

+

More flexible placeholders

@@ -263,9 +296,9 @@ $("select").select2({

And Select2 will automatically display the placeholder when the value of - the select is -1, which it is by default. This does not break - the old functionality of Select2 where the placeholder option was blank by - default. + the select is -1, which it will be by default. This does not + break the old functionality of Select2 where the placeholder option was + blank by default.

Display reflects the actual order of the values