diff --git a/index.html b/index.html index fd361b00..908e8d48 100755 --- a/index.html +++ b/index.html @@ -550,6 +550,7 @@ $("#e11").select2({ data: [{id: 0, text: 'story'},{id: 1, text: 'bug'},{id: 2, text: 'task'}] }); $("#e11_2").select2({ + createSearchChoice:function(term, data) { if ($(data).filter(function() { return this.text.localeCompare(term)===0; }).length===0) {return {id:term, text:term};} }, multiple: true, data: [{id: 0, text: 'story'},{id: 1, text: 'bug'},{id: 2, text: 'task'}] }); @@ -580,6 +581,27 @@ $("#e11_2").bind("change", show); +
+ +
+

Tagging Support

+ +

Select2 can be used to quickly set up fields used for tagging

+ +

+

Note that when tagging is enabled the user can select from pre-existing tags or create a new tag by + picking the first choice which is what the user has typed into the search box so far.

+
+
+

Example Code

+
+           
+
+
@@ -702,6 +724,24 @@ $("#e11_2").bind("change", show); <returns>stringMessage html + createSearchChoicefunction + Creates a new selectable choice from user's search term. Allows creation of choices not available via the query + function. Useful when the user can create choices on the fly, eg for the 'tagging' usecase. +
createSearchChoice(term)
+ + + + +
ParameterTypeDescription
termstringSearch string entered by user
<returns>object (optional)Object representing the new choice. + Must at least contain an id attribute.
+ If the function returns undefined or null no choice will be created. If a new + choice is created it is displayed first in the selection list so that user may select it by simply pressing + enter. + +

When used in combination with input[type=hidden] tag care + must be taken to sanitize the id attribute of the choice object, especially stripping + , as it is used as a value separator

+ query function @@ -760,6 +800,13 @@ $("#e11_2").bind("change", show);

If this element contains an array, each element in the array must contain id and text keys

Alternatively, this element can be specified as an object in which results key must contain the data as an array and a text key can either be the name of the key in data items that contains text or a function that retrieves the text given a data element from the array

+ tagsarray/function + Puts Select2 into 'tagging'mode where the user can add new choices and pre-existing tags are provided via + this options attribute which is either an array or a function that returns an + array of objects or strings. If strings are used instead of objects + they will be converted into an object that has an id and text attribute equal + to the value of the string. +
diff --git a/select2-master b/select2-master index 40843b1b..34a7f83f 160000 --- a/select2-master +++ b/select2-master @@ -1 +1 @@ -Subproject commit 40843b1b98740bc0d08fd0d083517cc1915c72ff +Subproject commit 34a7f83f7b3a33278920dc4d3468b41bd3aaa950