Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select2 - Add pending tag after losing focus

I am trying to use select2 for creating tags, but when I'm writing a new tag and I lose the focus of the field (click somewhere else, for example) what I was writing gets deleted.

Is there a way that after losing focus to the input of the select2, a new tag gets created?

like image 241
Jose Daniel Chacón Bogarín Avatar asked Sep 11 '25 20:09

Jose Daniel Chacón Bogarín


2 Answers

From the documentation:

$('select').select2({
  selectOnClose: true
});

This will capture the selection and create a tag if the user clicks elsewhere.

like image 75
kartikluke Avatar answered Sep 14 '25 23:09

kartikluke


It looks like the browser problem that i've seen.

It seems that the tags option doesn't work correctly on ie11.

I don't have the same behavior between ie11 and chrome (and edge). If you check the example https://select2.github.io/examples.html#tags with ie, it is not possible to add tag. You can start taping letter but you lose the focus immediately. Everything works on Chrome and Edge.

Is it this sort of problem, you've got.

like image 25
user2064344 Avatar answered Sep 14 '25 22:09

user2064344