Need to fix height and width of select2 multiple-select search box
Asked Answered
G

1

7

As and when I keep selecting multiple options in a select2 element, the text-area displaying the current selections keeps expanding, like the below:

enter image description here

I tried fix height of classes like select2-selection and select2-container. That did not help me. I ended up with something like the below.

Unsuccessful attempt

My requirement - I want to fix the height and width of the text area and all the options must be rendered within it. (Since, this will be part of a small pop-up and there are size restrictions).

Galvanotropism answered 30/3, 2015 at 11:38 Comment(2)
Could you please provide your question with test exampleCornejo
Point taken - I will use jsfiddle the next time I post a question. Thanks!Galvanotropism
G
13

This turned out to be fairly simple. There was a span element of class select2-selection--multiple as the parent of the lis. All I had to do was add overflow-y: auto and that did the trick. I was not aware of this property.

My select2 combobox, now, looks like the below.

enter image description here

For my further reading - overflow-y description in w3schools

Galvanotropism answered 30/3, 2015 at 11:46 Comment(2)
is it possible to just comma-separated values instead of a scroll bar with close sign selected names? I mean after selection of 2 or 3 name it will change to like 3 option selected. i.e. just number of option selected in search box of select2.Antefix
Worked like a charm! Thank you.Loopy

© 2022 - 2024 — McMap. All rights reserved.