Questions tagged [jquery-select2]

Select2 is a jQuery-based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.

Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.

Stack Snippet Starter Pack

HTML

<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.4/css/select2.min.css" rel="stylesheet" />
<script src="//code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.4/js/select2.min.js"></script>

<select class="select2">
  <option value="AL">Alabama</option>
  <option value="AK">Alaska</option>
  <option value="AZ">Arizona</option>
</select>

JavaScript

$('.select2').select2();

// get data when an option is selected
$('.select2').on('select2:select', function (e) {
    var data = e.params.data;
    console.log(data.id, data.text);

    // other data, eg get data-more:  
    $(data.element).data("more")
});

// language example changing no results
$('.select2').select2({ 
    language: { 
        noResults: function () { return "try again"; } 
    }
});

Useful links

Related Tags

5563 questions
2
votes
5 answers

Select2 Dynamic elements not reacting to event

I am using Select2 which works great. However I am using below code to create new dynamic select2 drop down but they do not react/open when clicking on them. var relationshipcounter = 0; $('#AddMoreRelationships').click(function () { var…
Dev01
  • 4,082
  • 5
  • 29
  • 45
2
votes
0 answers

select2 how to change style of ajax example to look like tag example

Using select2 I need to autocomplete tags with ajax. So everything works fine, except how it looks. I just don't understand how to make "loading remote data" example('#e6') to look like "auto tokenization" example('#e20'), I mean to look like usual…
antonovga
  • 43
  • 4
2
votes
2 answers

Select2 isn't working fine on a chrome extension popup

I'm experiencing a bad behavior of Select2 on a chrome extension using AngularJS and Angular-UI. The scenario Select2's content is loaded asynchronously via AngularJs $resouces module. What should happen? The content should be display when i click…
2
votes
2 answers

rails v3 with select2 gem ignoring client_side_validation error message

I'm using rails 3.0.9, client_side_validation gem and just tried to use select2 gem by using thier js and css file manually Downloaded the files from https://github.com/ivaynberg/select2/tags A simple form with a presence validation <%=…
2
votes
1 answer

Angular UI select2 array with objects is it possible?

Is there a easy way to have options as objects in array? Like following: $scope.search.categories = [{id: '1',name: 'first'},{id: '2',name: 'last'}];