Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Select2 default new tags key "tab" to "space"?

I am using tag supporting of Select2 for my tag editor, I know you can add a non-existed tag by enter tag and press key "tab"

My question is: I don't want any tags contain space, such as "space tag", so is there any way to set "space" key as a new tag trigger?

like image 811
Terry Zhao Avatar asked May 05 '13 19:05

Terry Zhao


1 Answers

(Answered in a question edit. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )

The OP wrote:

After some digging, I solved my question by

$("#e20").select2({
        tags:["red", "green", "blue"],
        tokenSeparators: [",", " "]
 });

The key point is the tokenSeparators attribute.

And the document of Select2 is useful.

like image 195
2 revs Avatar answered Sep 16 '22 22:09

2 revs