erk
erk

Reputation: 11

How to get list of options / data from an input-based select2 3.5 control

Were using 3.5.3, and have had no luck finding a way to do this.

After I select2-enable an input box with an array of values (using data: in the consructor options), is there a way to get that list back again, from the drop-down in question? We have utility code that needs to retrieve that list and disable an option, and that utility code doesn't have access to the same context that rendered the select2 to begin with (i.e. we don't have the array we used to build it, as this might affect many select2 controls on the page).

I would have expected something like $(control).select2('query', '') or .select2('search',''), but no luck. I'd even be happy just retrieving the initial constructor options, and getting the "data" item from that.

We can't use a select because we need the ability to dynamically add new user-typed options.

Upgrading to select2 4.0 isn't feasible, due to the degree of coupling our code has with 3.5 (I tried for weeks, and after hundreds of LOC changed, there was no end in sight).

I've searched for hours online, in stackoverflow and select2 documentation and elsewhere. If this answer already exists, I'm unable to find it.

Upvotes: 1

Views: 177

Answers (0)

Related Questions