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.
+ 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)
+
+
Parameter
Type
Description
+
term
string
Search 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
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
+
tags
array/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.
+