select2/select2

Creating a new tag with a value equal to the id of an existing option causes both the new tag and the existing option to be added as selections

Open

#3498 opened on Jun 19, 2015

View on GitHub
 (13 comments) (4 reactions) (0 assignees)JavaScript (25,772 stars) (6,283 forks)batch import
4.xconfirmed bugfeature: multi-selectfeature: selectionsfeature: tagginghelp wanted

Description

// input: red,
// var_dump($_POST["colors"]);
Array
(
    [0] => red
    [1] => red
)

// input: apple,green,water,
// var_dump($_POST["colors"]);
Array
(
    [0] => green
    [1] => green
)

// input: red,green,blue,yellow,
// var_dump($_POST["colors"]);
Array
(
    [0] => red
    [1] => green
    [2] => blue
    [3] => yellow
    [4] => red
)
<select name="colors[]" id="tags-example" multiple="multiple">
    <option value="red">apple</option>
    <option value="green">grass</option>
    <option value="blue">water</option>
    <option value="yellow">sun</option>
</select>
$('#tags-example').select2({
    tags: true,
    tokenSeparators: [',', ' '],
    maximumSelectionLength: 2
});

Please see the following fiddle to see what happens: http://jsfiddle.net/o1je0988/

Contributor guide