jquery-select2

Backbone/Marionette with select2 v4.0, editing the tags

十年热恋 提交于 2019-12-06 15:52:28
I have this fiddle which is an extension of the Backbone/Marionette playground fiddle. I included select2 js and css files. Is it possible to edit a tag that is not the last tag? You can edit by backspacing in the box, but it only lets you touch the last one. I would like it to act like a gmail 'to' list where you can double click on one and edit it, then it goes back to a tag on blur. this.$('#foo').select2({ data: [{ id: 1, text: "test1.com" }, { id: 2, text: "test2.com" }], multiple: true, allowclear: true, tags: [], placeHolder: "Click Here!", tokenSeparators: [',', ' '],

preloading external json into select box then after search getting specific results

纵然是瞬间 提交于 2019-12-06 15:19:52
so i am looking into loading external data in an select2 box where there is prepopulate results from the json i have two issue - getting the data in and then only loading the first few but when a user searches it passes the request to the rest and then the specific json is returned so the HTML is a simple as <input type="hidden" id="e21" style="width:300px;"/> the inital js is $(document).ready(function () { $('#e21').select2({ query: function (query){ var data = {results: []}; console.log(data); $.each(preload_data, function(){ if(query.term.length == 0 || this.text.toUpperCase().indexOf

How can I use multiple modified select2 selectboxes?

折月煮酒 提交于 2019-12-06 14:22:29
I have a jquery code, that is resorting my select2 tags. It is working well: $('select').select2({ placeholder: 'Select a month' }); $("select").on("select2:select", function(evt) { var element = evt.params.data.element; var $element = $(element); window.setTimeout(function() { if ($("select").find(":selected").length > 1) { var $second = $("select").find(":selected").eq(-2); $element.detach(); $second.after($element); } else { $element.detach(); $("select").prepend($element); } $("select").trigger("change"); }, 1); }); $("select").on("select2:unselect", function(evt) { if ($("select").find("

Add decorator to data adapter in Select2 version 4.x

蹲街弑〆低调 提交于 2019-12-06 12:41:45
I want to support the MaximumInputLength decorator for my custom Select2 Data Adapter . In my custom data adapter, the Utils.Decorate() call does not do anything. Looking at this gist , I could call the Decorator function in the same place where I initialize select2() , but that seems icky and not DRY, as I want to initialize many of these Select elements. In order to enable minimum input for ALL instances of MyDataAdapter, is it possible to decorate that adapter from the adapter itself? Is there a better way to do this? My select2() call: $('select').select2({ dataAdapter: MyDataAdapter,

Select2.js: why is id the same as text on change for removed?

戏子无情 提交于 2019-12-06 12:28:17
JSfiddle: http://jsfiddle.net/cjVSj/ I have a simple select2 with the range of possible tags set by the tags option and the preloaded tags set by values in the input field in the html. When the on change event fires on the select2, the removed item seems to lose its id, reporting instead its text value. To see the problem, adding a tag (e.g. west) correctly reports the added.id, but removing the existing east tags reports id = east, not 1356. Any insight into how to gain access to the id of a tag upon removal? HTML: <script> var tags = [{ "id": 1354, "text": "north", "restricted": false }, {

Check/Uncheck - ifChecked not working

独自空忆成欢 提交于 2019-12-06 12:19:53
UPDATE: I'm using the following plugin I'm trying to check if the checkbox is checked when the user refresh the page or reload the page and here is what I have used but I have done the debugging and it never execute the second IF condition $('input').on('ifChecked', function (event) { if ($("input#CreatePart").is(':checked')) { alert('checked'); } }); $('input').on('ifUnchecked', function (event) { if ($("input#CreatePart").is(':checked')) { alert('un-checked'); } }); <input checked="checked" class="icheck" data-val="true" data-val-required="The Create new Part field is required." id=

how to update data in select2 dropdown using ajax

巧了我就是萌 提交于 2019-12-06 12:01:02
问题 I have a select2 dropdown for location.select2 data is initialised on page load.I want to update the data at regular intervals using ajax.But when I update the data of select2 the select2 dropdown becomes read only jQuery("#e10_2").select2({ allowClear: true, minimumInputLength: 1, data:{ results: locationls, text: function(item) { return item.text; }}, formatSelection: format, formatResult: format }); 回答1: I don't really understand your question and think it needs some clarifying - but as

django-autocomplete-light - how to return a different field then a models primary key?

感情迁移 提交于 2019-12-06 08:49:25
问题 I am using django-autocomplete-light in a form for a model I want to use autocomplete on one of its field. the field is not a foreignkey or something, but just a integer field and for autocomplete I would actually like to use the same model then the form I am filling. The query set from autocomplete however returns the ID and I want to fill the field "projektnummer". Any clue how I can setup autocomplete so that it returns not the primary key of the model but some other field? also it seems

Select2 allowClear not working with dynamic dropdown list

☆樱花仙子☆ 提交于 2019-12-06 08:17:12
问题 I have tried a lot of ways to fix this problem. At a dynamic list loaded via ajax, I can't make allowClear work. Here is my jsFiddle HTML: <select id="first" class="init-select2" data-placeholder="First dropdown" data-allowclear="true"> <option></option> <option>First option</option> <option>Second option</option> </select> <select id="second" class="init-select2" data-placeholder="Second Dropdown" data-allowclear="true" disabled="disabled"> <option></option> </select> Javascript: $(function(

Select2 4.0.x Multi Checkboxes JS Plugin

吃可爱长大的小学妹 提交于 2019-12-06 07:36:41
问题 I'm using the Select2 control along with the Select2.Multi-checkboxes.JS plugin to allow multi-checkbox selection. The following demo shows that the control works properly with Select2 3.x : http://jsfiddle.net/wasikuss/gx93rwnk/ But when I cloned from this my own fiddle with Select2 4.0.x it stopped working. The checkboxes are no longer presented. What's the issue? http://jsfiddle.net/oa435z7s/ I copied all the elements from Fiddle 1 to Fiddle 2 by doing a direct Fork (Clone). Nothing was