jquery-select2

How to add class to select2 element in v4.0

你说的曾经没有我的故事 提交于 2019-12-09 14:06:08
问题 This is very similar to this question on how to add class to select2 element, however the answers there appear to target earlier versions of the framework which has undergone some breaking changes in v4.0 According to this issue to add an additional custom class to select2-container, there were several undocumented properties you could pass to the select2 constructor, including: containerCss , containerCssClass , dropdownCss , and dropdownCssClass . However in version 4 when I run the

select2 ajax won't display json data returned

℡╲_俬逩灬. 提交于 2019-12-09 13:15:38
问题 Here is what the json string looks like that gets returned from my coldfusion page: [{"client":"Asante","id":12},{"client":"City of Lancaster","id":14},{"client":"Massey Energy","id":35},{"client":"Northeast Utilities","id":68},{"client":"Washtenaw","id":50}] . Firebug claims everything is working perfectly but none of the data shows up in the select2 plugin. Does anyone know what the problem might be? Should it be returning column names or something? select2 call: $(".select").select2({

How to handle ordered many-to-many relationship (association proxy) in Flask-Admin form?

有些话、适合烂在心里 提交于 2019-12-09 13:15:33
问题 I have a many-to-many relationship between declarative models Page and Survey , which is mediated by association proxies because the order in which pages appear in a survey is important, so the cross-linking table has an additional field. from flask.ext.sqlalchemy import SQLAlchemy from sqlalchemy.ext.associationproxy import association_proxy db = SQLAlchemy() class Page (db.Model): id = db.Column(db.Integer, primary_key = True) surveys = association_proxy('page_surveys', 'survey') class

Select2 dropdown allow new values by user when user types

巧了我就是萌 提交于 2019-12-09 06:59:58
问题 The select2 component can be configured to accept new values, as ask in Select2 dropdown but allow new values by user? And you can see it at: http://jsfiddle.net/pHSdP/646/ the code is as below: $("#tags").select2({ createSearchChoice: function (term, data) { if ($(data).filter(function () { return this.text.localeCompare(term) === 0; }).length === 0) { return { id: term, text: term }; } }, multiple: false, data: [{ id: 0, text: 'story' }, { id: 1, text: 'bug' }, { id: 2, text: 'task' }] });

Passing Custom Headers to Ajax request on Select2

烂漫一生 提交于 2019-12-09 02:53:39
问题 We are trying to implement Ajax Remote data loading in Select2:- $scope.configPartSelect2 = { minimumInputLength: 3, ajax: { url: "/api/Part", // beforeSend: function (xhr) { xhr.setRequestHeader('Authorization-Token', http.defaults.headers.common['Authorization-Token']); }, // headers: {'Authorization-Token': http.defaults.headers.common['Authorization-Token']}, data: function (term, page) { return {isStockable: true}; }, results: function (data, page) { // parse the results into the format

Select2 with ajax gets initialized several times with Rails turbolinks events

牧云@^-^@ 提交于 2019-12-08 23:19:52
问题 I am a developing a Ruby On Rails app using Rails 4.2.6. I am using Turbolinks alongside jquery.turbolinks (sorry I could'nt post the links to those elements as I am a newbie on the site). My problem is very simple but I just can't solve it. Here it is: I have a form fetched through AJAX <div class="card-footer"> <a class="btn btn-sm btn-primary-outline" data-remote="true" href="/profiles/Mke5kA/positions/new"><i class="fa fa-plus"></i> Nouvelle expérience professionnelle</a> <div id="new

Why does the select2-removing event not trigger in select2 with allowClear?

◇◆丶佛笑我妖孽 提交于 2019-12-08 21:43:10
问题 I want to hook an event in my select2 once it gets cleared. The select2 was initalized with allowClear: true . Yet the event $select.on('select2-removed', function(event) { console.log(event); }); does not trigger when resetting the select2 with the clear button. 回答1: According to the select2 source code, the clear method use the event select2-clearing instead of select2-removing . So you should listen to this event too. select2-clearing and select2-removing are triggered before the removal.

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 sort the select2 (jQuery plugin) options alphabetically?

早过忘川 提交于 2019-12-08 14:43:47
问题 I want to sort the select2 options in alphabetical order. I have the following code and would like to know, how can this be achieved: <select name="list" id="mylist" style="width:140px;"> <option>United States</option> <option>Austria</option> <option>Alabama</option> <option>Jamaica</option> <option>Taiwan</option> <option>canada</option> <option>palau</option> <option>Wyoming</option> </select> $('#mylist').select2({ sortResults: function(results) { return results.sort(); } }); I want to

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: $('