I am using select2 4.0.3. I have a select2 box to enter email addresses, and I would like to make sure that all email addresses are included in
.val()
$('.invite-emails-field')
$('.invite-emails-field').val()
test1@example.com
test2@example.com
test3@example.com
$('.invite-emails-field').select2({
tags: true,
tokenSeparators: [',', ' '],
selectOnBlur: true
});
selectOnBlur
test3@example.com
.val()
test3@example.com
You need to add selectOnClose
and set it to true
so that it creates the tag for you when you close / click off of the search input.
$('select').select2({
selectOnClose: true
});
See the official documentation here: https://select2.github.io/options.html#can-i-select-the-highlighted-result-when-the-dropdown-is-closed