jquery-select2-4

select2 removes default options when using ajax

大城市里の小女人 提交于 2019-12-10 15:13:20
问题 I am trying to setup my pre defined select options in select2 with ajax but when I am using the ajax and clicking on the select2 it removes the html options I had there before, any idea how can I make it to leave the options as they are and not remove them until I am typing some unrelevant char? I believe it is not clear so I made fiddle with both cases so you will get better understanding the HTML <select id="e1" style="width:300px"> <option value="AL">Alabama</option> <option value="Am"

Jquery Select2 plugin version check

▼魔方 西西 提交于 2019-12-10 03:45:36
问题 In my project I check if the Select2 plugin was loaded in this way if (jQuery().select2) But now I will try to verify what kind of version (3.5.X or 4.X) of Select2 plugin was loaded. I thought maybe you could check if there is an option/function introduced in version 4.X that is not present in the version 3.5.X. According to you, is it doable? How might I do it? Thank you 回答1: There is a new isOpen method in Select2 4.0. You can use something like this in your developer toolbar: try { $("#a

Select2 default options with ajax

僤鯓⒐⒋嵵緔 提交于 2019-12-10 03:01:11
问题 I have next html structure <select class="change_item_dropdown_ajax form-control" id="item_id" name="item_id" onchange="updateData(this, this.value, 16)" > <optgroup label="System Data"> <option value="17">Test</option> <option selected="selected" value="18">System</option> </optgroup> </select> Javascript $(".change_item_dropdown_ajax").select2({ ajax: { url: "get_user_items", dataType: 'json', delay: 250, theme: "classic", data: function (params) { return { q: { name_contains: params.term }

maximumSelectionSize isn't working in Select2

被刻印的时光 ゝ 提交于 2019-12-08 19:39:32
问题 I have a multivalue select, and I want to set the restriction on number of selected items using the select2 library. Documentation says that I should set maximumSelectionSize during the object initialization. Unfortunately, the following code doesn't work: $(document).ready(function () { $("#select_demo").select2({ maximumSelectionSize: 3 }); }); My html selectbox: <div class="form-group"> <select id="select_demo" multiple="multiple" class="form-control select2 select2-container-multi">

how to change select2 value programmatically

爱⌒轻易说出口 提交于 2019-12-08 14:29:51
问题 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 tested: $('#select_id').val('val').trigger('change.select2'); $('#select_id').val('val').trigger('change'); $('#select_id').val('val').change() It works one or two times then it stops working (randomly) It works fine only when I change the select2 back to 3.x.x 回答1: $('

using select2 gem with acts_as_taggable gem on rails

感情迁移 提交于 2019-12-08 11:44:30
问题 Im using select2-rails gem in my rails app. I found a problem here: Problem in tag_list. As u see it starts with ["",...] what wrong. Because of this my tag_list became empty after submitting. Without select2 it works fine. Can any one help? My erb code <%= f.label :tag_list, "TAGS" %><br> <%= f.select :tag_list, options_for_select([['Asst', 'As'], ['Mouse', 'Mm'], ['Yeast', 'Sc']]),{},:multiple => true, :class =>"category" %> 回答1: There are two problems here: 1) the tag_list parameter is not

When attempting to create a custom data adapter for a select2 combo box, what is causing “Uncaught TypeError baseName split is not a function”?

拟墨画扇 提交于 2019-12-08 10:02:37
问题 I would like to use a select2 combobox with pagination for a local data array (no ajax call). To that end I'm looking at custom DataAdapter. The code to initialise the custom adapter fails. I've tried creating a custom data adapter similar to this answer. When adding the custom data adapter to the select2 object $.fn.select2.amd.require( 'select2/data/customAdapter', ['select2/data/array', 'select2/utils'] I get this error (in chrome and firefox) jquery-3.4.1.js:3850 Uncaught TypeError:

How to set data-* from datasources in Select2?

∥☆過路亽.° 提交于 2019-12-08 06:37:54
问题 I am using Select2 as follow: $('select#fields').select2({ placeholder: 'Select a field', data: data.fields }); data.fields is a JSON like this one: "fields": [ { "id": "companies_id", "text": "companies_id", "data-type": "int" }, { "id": "parent_companies_id", "text": "parent_companies_id", "data-type": "int" }, { "id": "client_of_companies_id", "text": "client_of_companies_id", "data-type": "int" }, { "id": "asset_locations_id", "text": "asset_locations_id", "data-type": "int" }, { "id":

how to get the data-* value of a selected option in select2?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 03:33:16
问题 This is like a second part of this topic and right now I need to be able to read dynamic data-* properties from one select to the other. What this mean? First take a look to the following image: What you're seeing there is what the following code does: // This turn 1st and 3rd into select2 $('#module, #conditions').select2(); // This turn 2nd into select2 using data from a datasource $('select#fields').select2({ placeholder: 'Select a field', data: data.fields }); As I posted in the

Add fontawesome icons into select2 V4 dropdown items

心已入冬 提交于 2019-12-07 16:31:25
问题 I am trying to display fontawesome icons in the Select2 v4 dropdown items. But the dropdown is displaying the html and not generating the actual icon. This method works with select2 V3 but does not seem to with v4. Any help is appreciated. Thank you HTML <div class="select2-wrapper"> <select class="input icons_select2"> <option value="fa-dribbble" data-icon="fa-dribbble">Dribbble</option> <option value="fa-dropbox" data-icon="fa-dropbox">Dropbox</option> <option value="fa-facebook" data-icon=