select2: Pasting does not create the tags
Pasting a string like “marc,edward,jorge” does not create the tags.
$('#tagSelector').select2({
tags: true,
tokenSeparators: [','],
multiple: true
});
Fiddle here:
Any idea on how to solve this?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 28 (4 by maintainers)
Doesn’t work here - reopen please.
Tried pasting with a@de.de,b@de.de,c@de.de (separator should be “,” )
@chrilehner I did it listening to
onpasteevent on select2’s text input (.select2-search__field). In the callback, i get clipboard content, append to it a tag separator, set it as the input value and trigger the keyup event.That’s not the cleanest solution ever imagined but at least it is working without modifying the library.
For example (I used arrive.js here to watch for DOM changes)
Notice that I set event listener using the inline onpaste property : when I was doing it programmatically (
addEventListener,or jQuery’s.on('paste',...)), my event listener was getting removed by select2 as soon as I selected an element or added a tag.