Questions tagged [jquery-select2-4]

Select2 4.0 was released in April 2015 and is a complete rewrite of the Select2 code base. Please only use this tag if your issue is specific to this version.

Select2 4.0 was released on April 26th, 2015 and is a complete from-scratch rewrite of the code base.

Tag questions that address any of the following

  • The new adapter framework
  • Improved searching and matching
  • New flexible placeholders
  • Migrating from Select2 3.5.2

Make sure to also tag the question with .

See the Select2 4.0 release notes for more information.

509 questions
110
votes
14 answers

How can I set the initial value of Select2 when using AJAX?

I have a select2 v4.0.0 being populated from an Ajax array. If I set the val of the select2 I can see via javascript debugging that it has selected the correct item (#3 in my case), however this is not shown in the select box, it is still showing…
Greg
  • 1,803
  • 3
  • 18
  • 26
68
votes
4 answers

How do you modify "No Results Found" language in Select2 v4.0

I attempted to use the "language.noMatches" option when initiating Select2 and its throwing an undefined function? How do I go about modifying that bit of text? I would like to include a html button that would add the input from the user if it…
Anthony Conklin
  • 681
  • 1
  • 5
  • 3
51
votes
8 answers

How to render html in select2 options

In this example of data loaded from a remote source I can see images and other html elements rendered as options. I'd like to accomplish the same thing using data in a local array. I've tried building an array as described in the documentation and…
47
votes
17 answers

Select2 open dropdown on focus

I have a form with multiple text inputs and some select2 elements. Using the keyboard to tab between fields works fine - the Select2 element behaves like a form element and receives focus when tabbing. I was wondering if it is possible to open the…
andreivictor
  • 7,628
  • 3
  • 48
  • 75
35
votes
7 answers

how to change select2 value programmatically

I have a select2 box in bootstrap modal, I want to change the value of the select2 box but it didn't work. I tried every single solution in previous posts and results but none of them got it work. I use select2 4.0.2, I…
Chaanbi Kada
  • 371
  • 1
  • 3
  • 5
33
votes
7 answers

How to programmatically inject search queries into Select2 v4?

I've built a web-app using a Select2 search box, which connects to our backend via AJAX. The search box passes the query (say "APPLES") to the backend, which then updates the page. How do I programmatically inject search queries into the search box?…
vgoklani
  • 10,685
  • 16
  • 63
  • 101
32
votes
1 answer

Having trouble working with SelectWoo instances of Select2 within WooCommerce

I am using Select2 within WooCommerce in some of my own custom areas and I am targeting it with some code to add and removes certain classes and it's working fine except for the SelectWoo instances used by WooCommerce themselves do not add the class…
Brett
  • 19,449
  • 54
  • 157
  • 290
27
votes
5 answers

How to disable creating new tags with select2 v4.0?

I've been trying out the new Select2 v4.0 which has a lot of improvements. I'm mainly interested in the tags feature. I want to be able to search for tags via ajax and only be able to select a tag from the shown results and not be able to create new…
tftd
  • 16,203
  • 11
  • 62
  • 106
24
votes
1 answer

Select2 v4 how to paginate results using AJAX

I'm trying to paginate results (every 25 rows) using Select2 4.0, but I don't know how to achieve it. Does somebody know how to do it? If the user reach the end of the 25 rows and if there is more rows I would like to load it and show it. Here is…
Diego
  • 243
  • 1
  • 2
  • 5
21
votes
3 answers

select2 search - match only words that start with search term

I migrated from chosen to select2 plugin because it works better for me, but its documentation is very poor when compared to chosen. Could anyone tell me what option(s) should be used to make select2 search function to filter words that just begin…
Mindaugas Li
  • 1,071
  • 5
  • 15
  • 37
19
votes
4 answers

How do I display the selected tags in Select2 below the dropdown box?

I am using Select2 (version 4) with tags and would like to have the selected choices display below the input field. So instead of: Rather have: Is this possible and if so how do I achieve that? EDIT: Code is: