jquery-select2

jQuery-select2 - Get values in the order they were selected

我只是一个虾纸丫 提交于 2019-12-10 16:47:37
问题 I'm developing a form with a number of multiselects. I use Select2 library for that. $(".chosen-select").select2({ allow_single_deselect: true, width: "150px" }); ...... <select id="ship2" class="chosen-select" data-placeholder="Select vessel"> <option></option> <option value="value1">title1</option> <option value="value2">title2</option> </select> The problem is that when I try to get selected values they are returned in the order they are specified in <select> element, not the order they

Allow dynamic choice in Django ChoiceField

人盡茶涼 提交于 2019-12-10 15:59:46
问题 I'm using Select2 in my application for creating tags-like select dropdowns. Users can select number of predefined tags or create a new tag. Relevant forms class part: all_tags = Tag.objects.values_list('id', 'word') # Tags tags = forms.ChoiceField( choices=all_tags, widget=forms.Select( attrs={ 'class': 'question-tags', 'multiple': 'multiple', } ) ) The problem is that Django won't allow custom tags(choices) upon validation. There error I'm getting looks like this: Select a valid choice.

How to add an image in Select2 options?

主宰稳场 提交于 2019-12-10 15:34:51
问题 I have a select: <select data-bind="options : PeriodeOptions, optionsValue : 'Periode', optionsText : function(item) { return AddLock(item)}" id="SelectPeriode"></select> And I have my fucntion; //am - Fonction permettant d'ajouter le cadenas à côté de la Periode si elle est cloturée function AddLock(pItem) { if (!pItem.IsCloturePeriode) return pItem.Periode; var lTemplate = $('<span>' + pItem.Periode + '<img src="/Ressources/Images/Locked.png"/></span>'); return lTemplate; }; It sends me an

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"

Select2 acts very different with Uncaught query function not defined for Select2 <select2-id>

那年仲夏 提交于 2019-12-10 14:57:08
问题 I load values for select2 like the following way. Declare the Type var AdjustmentType = Backbone.Model.extend({ url : Hexgen.getContextPath("/referencedata/adjustmenttype") }); create instance for the Type var adjustmentTypes = new AdjustmentType(); load the values to select2 box adjustmentTypes.fetch({ success : function() { for(var count in adjustmentTypes.attributes) { $("#adjustment-type").append("<option>" + adjustmentTypes.attributes[count] + "</option>"); } } }); $("#adjustment-type")

Select2 - Link on formatNoMatches

坚强是说给别人听的谎言 提交于 2019-12-10 13:56:42
问题 I'm using Select2 to enhance my <select> input. I populate the <options> with coldfusion and sql. I want to use formatNoMatches to add the option if there are no matches in the user search. I don't want to use a multiple select because it does not work with my coldfusion, plus it would be much simpler to simply add a click event to formatNoMatches . Somewhere in select2.js, there is code that is stopping mouse events from occurring for formatNoMatches . Is there a way to hack it that will

Extend div outside bounds of iFrame?

余生长醉 提交于 2019-12-10 13:53:32
问题 Is it possible to extend content beyond the bounds of an iframe? In my case, I was formerly rendering a native <select> control inside of an iframe. As a native control, when it rendered, the dropdown was able to occupy space outside of the iframe. I recently converted the dropdown to use select2, which rebuilds the dropdown using various <span> elements. The problem is now it gets cutoff within the <iframe> : I've tried setting the overflow to visible, but that doesn't work: iframe {

select2 - initselection error

你离开我真会死。 提交于 2019-12-10 13:12:10
问题 I am getting the following error when using select2 plugin on initSelection . Error: Uncaught Error: No select2/compat/initSelection is the error I am getting. Hope somebody helps me in sorting out the inistselection issue. JS: $(".doctor_id_pat").select2({ placeholder: "Search Users", minimumInputLength: 2, ajax: { url: "/listallergiesajax", dataType: 'json', data: function(term) { return { q: term }; }, results: function(data, page) { return { results: $.map(data, function(item) { return {

Write new select2 option tags to local database in express

假装没事ソ 提交于 2019-12-10 13:10:09
问题 I am using select2 in an express app to make an input box where users can select subjects from a list, and can update this list with any newly added options . The thing I'm struggling with is that select2 runs client-side, whereas any data I use to seed my <option> tags (that I want to append new options to) is server-side. I want users to be able to add subjects that don't exist in the original list, so that future users will be presented with newly added options (as well as the original

How to pass <option> attributes to select2?

你说的曾经没有我的故事 提交于 2019-12-10 12:33:06
问题 I'm using Select2 4.0. I have a list of options, some of which are "deleted" and I want to signify which are which. My select element is like this: <style>.deleted { color: red; }</style> <select name="itemid" id="item-list" tabindex="1"> <option></option> <option value="1">Item 1</option> <option value="2" class="deleted">Item 2</option> <option value="3">Item 3</option> </select> And it's initialised like this: <script src="/static/js/select2.min.js"></script> <script> $(function() { $("