jquery-select2

select2 on success retrieve newly created tag id

北战南征 提交于 2019-12-06 07:35:58
In select2 I have tags loaded by AJAX, if the tag is not found in the db then the user has the option to create a new one. The issue is that the new tag is listed in the select2 box as a term and not as the id (what select to wants - especially becomes a problem when loading the tags again if the user wants to update since only the term and not the id is stored in the db). How can I, on success of adding the term, make it so that select2 recieves the ID and submits the ID instead of the tag name/term? $(document).ready(function() { var lastResults = []; $("#project_tags").select2({ multiple:

In Select2, how do formatSelection and formatResult work?

孤人 提交于 2019-12-06 05:39:36
问题 I'm using Select2 (http://ivaynberg.github.io/select2/) to have an input field of a form (let's say its id is topics ) to be in tagging mode, with the list of existing tags (allowing the user to choose some of these tags, or to create new ones) being provided by an array of remote data. The array ( list.json ) is correctly got from my server. It has id and text fields, since Select2 seems to need these fields. It thus looks like this: [ { id: 'tag1', text: 'tag1' }, { id: 'tag2', text: 'tag2'

Select2 Loading remote data Example not working

☆樱花仙子☆ 提交于 2019-12-06 03:48:40
问题 this example is not working at all.. Can someone please create this in jfiddle???? Here is the example site. https://select2.github.io/examples.html Thank you so much for the help!!! 回答1: Found an answer for this. See the below example. Hope this helps others! Here is the Fiddle Here is the script : function formatRepo (repo) { if (repo.loading) return repo.text; var markup = '<div class="clearfix">' + '<div class="col-sm-1">' + '<img src="' + repo.owner.avatar_url + '" style="max-width: 100%

Prevent multiple select element from automatically sorting the value assigned to it basis the order of the indexes in the options

时光总嘲笑我的痴心妄想 提交于 2019-12-06 01:47:32
问题 I am using the select2 plugin to convert a multiple select html element to a more presentable format. Also I don't think my question is very much dependent on the plugin. What the plugin does internally is - this.select.val(val); where this.select points to the hidden multiple select element. On feeding the function above a val of say - 2,4,0 , the value stored as confirmed when I do an alert(this.select.val()) is 0,2,4 , i.e. with automatic unwanted sorting according to the order of the

How to load model data to Select2 dropdown which uses Ajax filtering in Yii

浪子不回头ぞ 提交于 2019-12-06 01:29:34
I use the following select2 Yii widget in my view to populate a drop-down list. Since the data necessary for the preparation of the select list consists of more than 2K records I use select2 with minimumInputLength parameter and an ajax query to generate partial result of the list based on user input. If I create a new record I have no problem at all. It populates everything fine and I can save data to my database. However I don't know how to load saved data back to this drop-down during my update action. I read somewhere that initselection intended for this purpose but I couldn't figure out

Using $(this) in select2

回眸只為那壹抹淺笑 提交于 2019-12-06 00:41:31
I'm trying to read a collection from the html5 data-attribute of the input that is converted to select2 to create tags. This is working when I have one input: $(".tags").select2( width: '220px' tags: $(".tags").data('collection') ) But I will like to do it more safe using the data of the element itself, I tried this: $(".tags").select2( width: '220px' tags: $(this).data('collection') ) But it fails with the error: Uncaught query function not defined for Select2 investigador_aplicaciones Do you know if it is posible to use the element itself with a specific selector like $(this)? You can do

Need to fix height and width of select2 multiple-select search box

烂漫一生 提交于 2019-12-05 19:24:07
As and when I keep selecting multiple options in a select2 element, the text-area displaying the current selections keeps expanding, like the below: I tried fix height of classes like select2-selection and select2-container . That did not help me. I ended up with something like the below. My requirement - I want to fix the height and width of the text area and all the options must be rendered within it. (Since, this will be part of a small pop-up and there are size restrictions). This turned out to be fairly simple. There was a span element of class select2-selection--multiple as the parent of

Firing event when user clicks no matches found jquery plugin select2

笑着哭i 提交于 2019-12-05 18:49:59
Is there a possible way to fire an event when user clicks the no matches found message in jquery plugin select2??? i need that event for my project i have tried this code but it seems not working $('.select2-no-results').live('click',function(){ alert("Yes"); }); $('.select2-drop-active').delegate('li.select2-no-results','click',function(){ alert('Hello'); }); is there a possible solution for this???? technology_dreamer Hope my solution helps with your problem: *Select2 configuration var $select2 = $('#select2_id').select2( { //Your parameters formatNoMatches: Not_Found }); *Error handling

Select2 Custom Matcher for Non-Adjacent Keywords

我是研究僧i 提交于 2019-12-05 17:15:33
I use Select2 in my app to allow for searching a dropdown with about 1200 options. I am currently making use of the default implementation of Select2's matcher, which works well as long as keywords are adjacent in the search results: function(term, text) { return text.toUpperCase().indexOf(term.toUpperCase())>=0; } For example, a search for 'stackoverflow question' returns option 'Stackoverflow question about Select2' I would however else like the matcher to return results based on non-adjacent keywords. For instance, I would also like it to return the above option when searching for

Select2 v4 unable to tab into, press enter, and then select, with Firefox (aka mouseless access)

微笑、不失礼 提交于 2019-12-05 15:57:56
问题 I am currently unable to tab into a Select2 enabled <select> element in Firefox (38.0.5) - in other words, cannot access to select <option> in a mouseless manner. In Chrome, you can tab through a form and press enter in order to start selecting an item in the Select2 select element. I have not tested in other browsers, but before submitting an actual bug report I want to verify whether others are experiencing the same issue? You can duplicate on the demo page. Select2 v4.0.0 Twitter Bootstrap