chadb768
chadb768

Reputation: 473

Get value of Select2 custom tag using Jquery

Using Select2, I have a selectBox that I want users to be able to type out their own custom tags to (just like stackoverflow's question tagging system). Here's what I'm working with currently:

Javascript:

$(".custom").select2({tags: true, tokenSeparators: [',', ' ']})
var $customSelect = $(".custom");
$customSelect.on("Select2:select", function(e) {
    console.log("Custom Selection: " + e.params.data);
});

HTML:

<select class="selectBox custom" multiple="multiple"></select>

The selectBox in the HTML has no options because I want users to define them themselves by typing in tags. The javascript worked fine for my non-custom selectBoxes but can't seem to grab any data for my custom ones.

Upvotes: 0

Views: 106

Answers (1)

Kevin Brown-Silva
Kevin Brown-Silva

Reputation: 41719

The issue here is that you are catching the wrong event.

Select2 triggers all events using the lowercase name, so you should be catching select2:select, not Select2:select.

Upvotes: 1

Related Questions