How can I use a textarea instead of the default text input when using select2?

I've tried changing the input tag to a textarea tag, but it seems that after the select2 js initialization is done, the element is converted to an input element.

The reason I want a textarea is because I want to signify to my users that they'll be choosing many items, so having multiple rows will be useful for my intentions.

有帮助吗?

解决方案

Do you need to? You can set the height using css

.select2-container, .select2-choices { height: 200px;}

Edit: or even better you can just style a class on your input before you apply .select2() to it and the container will automatically append that class to the container. You can then make it look like a textarea.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top