jquery-select2

Integrate Select2 into the Angular2 app

 ̄綄美尐妖づ 提交于 2019-11-29 01:31:45
问题 I'm trying to integrate Select2 into the Angular2 app I'm building. I managed to get select2 running and my multiple selects are transformed as expected. My problem now is how am I supposed to get the selected values and which event should I use for the binding. I tried binding (change) event on the select element but nothing happened. Maybe I should use some other event on the created by the plugin select2-container element? The select2 plugin is integrated following this answer. Anybody

select2 load data using ajax cannot select any option

大憨熊 提交于 2019-11-29 01:29:48
I have the following code (javascript): $('#cbxConnections').select2({ minimumInputLength: 0, multiple: false, allowClear: true, placeholder:{ text:"@Diccionario.Connections", id:" @Diccionario.Connections" }, ajax:{ url:'@Url.Action("GetActiveConnections","Admin")', dataType: 'json', type:'post', data:function(params){ return { q: params.term }; }, processResults: function(data,page){ return { results: data }; } }, escapeMarkup: function (markup) { return markup; }, templateResult: function(response){ return '<div>'+response.Name+'</div>'; }, templateSelection: function(response){ return

How to test a Select2 element with capybara DSL?

╄→尐↘猪︶ㄣ 提交于 2019-11-29 01:21:11
I have a Select2 element on a page that loads results via ajax. Would like to test this with capybara/rspec (using the poltergeist driver), but since the Select2 element actually starts out as a hidden field, and then populates a <ul> once results are processed, none of the normal select , fill_in or choose helpers will work. What I have now is something like it "should have a search field for events" do click_link "Select an Event" # this works as expected within('.select2-container') do # works find('.select2-search input').set(event.description[0,5]) # won't work! find(:xpath, "li[text()='#

jquery select2 - not working

心不动则不痛 提交于 2019-11-29 01:15:29
I am using select2 plugin(ivaynberg.github.io/select2). I am trying to display a dropdown(select). It is getting all the items in data.php as options. However select2 is meant to be autocomplete plugin and should search for the search term a client input, and display the matching results only. At the moment it is displaying all the items and not getting the search results. Sorry for my language data.php is echoing out this: [{ "id": "1", "text": "item1", "exercise": "blah text" }, { "id": "2", "text": "item2" } ] The code is: $(document).ready(function () { $('#thisid').select2({

Select2 and initSelection callback

耗尽温柔 提交于 2019-11-29 00:06:44
问题 On page load, I'm trying to use initSelection to select ID 60 (specified value of the input field) . I can't seem to get it to work properly. The PHP scripts work great and return the correct values, but how do I get the JS to do the callback correctly? JavaScript: $(document).ready(function() { $('#editAlbumArtistId').select2({ placeholder: 'Search names', ajax: { url: "/jQueryScripts/jQuerySelectListArtists.php", dataType: 'json', quietMillis: 100, data: function (term, page) { return {

Select2 with createSearchChoice uses newly created choice for keyboard entry even given a match, bug or am I missing something?

那年仲夏 提交于 2019-11-28 23:21:15
I'm using Select2 (version 3.4.0) to populate a tag list. The tags are matched against existing ones via ajax call, and I'm using createSearchChoice to allow creating new tags. The code works so far, and looks something like this: $(mytags).select2({ multiple: true, placeholder: "Please enter tags", tokenSeparators: [ "," ], ajax: { multiple: true, url: myurl, dataType: "json", data: function(term, page) { return { q: term }; }, results: function(data, page) { return data; } }, createSearchChoice: function(term) { return { id: term, text: term + ' (new)' }; }, }); All pretty standard, except

Setting initial values on load with Select2 with Ajax

依然范特西╮ 提交于 2019-11-28 22:29:25
I have select2 controls set up with Ajax (have both single and multiple). I'm trying to have some values on page load but I'm not able to get this to work however. My code for select2 is given below: function AjaxCombo(element, url, multival ){ // multival = true or false multival = multival || false; $(element).select2({ minimumInputLength: 2, multiple: multival, separator: '|', ajax: { url: url, dataType: 'json', data: function (term, page) { var targetname = $(this).attr('name'); var target = targetname.slice(targetname.indexOf("[")+1, targetname.indexOf("]")); return { targettype: "search"

select2 force focus on page load

时光毁灭记忆、已成空白 提交于 2019-11-28 21:01:43
I am trying to make a select2 box appear in its focused state on page load. I have tried the following: $('#id').select2('focus'); $('#id').trigger('click'); $('#id').trigger('focus'); Only the first line seems to have any effect, and it does focus the select2 field, however it requires an additional keypress to display the search field, and to allow typing in search string. Therefore, if you load the page and start typing: "Search", the "S" will open the search box and then the remainder of the keys will be entered into it, so you'll be searching "earch" According to the Select2 documentation

$watch not firing on data change

自古美人都是妖i 提交于 2019-11-28 20:01:31
I have a watch setup against the model of a ui-select2 dropdown (from ui-bootstrap). The watch fires on load but not on data changes and I can't figure out why. It isn't the usual problem of not $apply'ing the model change or not using the third parameter for equality comparison (at least from my code). What do I need to do to get it to fire? Here is a plunk demonstrating the issue. shaunhusain I fixed some stuff. http://plnkr.co/edit/5Zaln7QT2gETVcGiMdoW?p=preview The JS var myMod = angular.module("myApp",[]).controller("MainController", function($scope){ $scope.myModel = {selectedId:null}; }

How to get Selected Text from select2 when using <input>

本小妞迷上赌 提交于 2019-11-28 17:09:21
I am using the select2 control, loading data via ajax. This requires the use of the <input type=hidden..> tag. Now, I want to retrieve the selected text. (The value property in the data-bind expression sotres the id only) I have tried $(".select2-chosen").text() , but this breaks when I have multiple select2 controls on the page. As of Select2 4.x, it always returns an array, even for non-multi select lists. var data = $('your-original-element').select2('data') alert(data[0].text); alert(data[0].id); For Select2 3.x and lower Single select: var data = $('your-original-element').select2('data')