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

1

11

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?

Alfi answered 5/5, 2013 at 19:3 Comment(0)
L
9

(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.

Lorsung answered 5/5, 2013 at 19:4 Comment(1)
How to create keydown event in select2? I want to trigger a event for spacebarHedy

© 2022 - 2024 — McMap. All rights reserved.