jquery-select2

How to Set Selected value in Multi-Value Select in Jquery-Select2.?

为君一笑 提交于 2019-12-17 08:37:43
问题 hi all i am binding my dropdown with Jquery-Select2. Its working fine but now i need to Bind my Multi-Value selectBox by using Jquery-Select2. My DropDwon <div class="divright"> <select id="drp_Books_Ill_Illustrations" class="leaderMultiSelctdropdown Books_Illustrations" name="drp_Books_Ill_Illustrations" multiple=""> <option value=" ">No illustrations</option> <option value="a">Illustrations</option> <option value="b">Maps</option> <option value="c">Portraits</option> </select> </div> From

How to set selected value of jquery select2?

佐手、 提交于 2019-12-17 07:15:38
问题 This belong to codes prior to select2 version 4 I have a simple code of select2 that get data from ajax $("#programid").select2({ placeholder: "Select a Program", allowClear: true, minimumInputLength: 3, ajax: { url: "ajax.php", dataType: 'json', quietMillis: 200, data: function (term, page) { return { term: term, //search term flag: 'selectprogram', page: page // page number }; }, results: function (data) { return {results: data}; } }, dropdownCssClass: "bigdrop", escapeMarkup: function (m)

Clear dropdown using jQuery Select2

白昼怎懂夜的黑 提交于 2019-12-17 06:13:02
问题 I'm trying to programmatically clear a drop down using the fantastic Select2 library. The drop down is dynamically filled with a remote ajax call using the Select2 query option. HTML: <input id="remote" type="hidden" data-placeholder="Choose Something" /> Javascript: var $remote = $('#remote'); $remote.select2({ allowClear: true, minimumInputLength: 2, query: function(options){ $.ajax({ dataType: 'json', url: myURL + options.term, error: function(jqXHR, textStatus, errorThrown){ smoke.alert

“query function not defined for Select2 undefined error”

穿精又带淫゛_ 提交于 2019-12-17 05:41:11
问题 Trying to use Select2 and getting this error on multiple item input/text field: "query function not defined for Select2 undefined error" 回答1: Covered in this google group thread The problem was because of the extra div that was being added by the select2. Select2 had added new div with class "select2-container form-select" to wrap the select created. So the next time i loaded the function, the error was being thrown as select2 was being attached to the div element. I changed my selector...

Select2 drop down change event not working

别来无恙 提交于 2019-12-14 03:45:45
问题 I am using Select2 drop down and I need to do some functionalities based on the the drop down selection. I have tried the following code, but it didn't worked for me. $eventSelect.on("select2:select", function (e) { log("select2:select", e); }); $eventSelect.on("change", function (e) { log("change"); }); Can anyone tell me how can I make this work? 回答1: I am using select2 version 3.3.2 and the following code is working for me $("#id").on("change", function () { debugger; }); 回答2: You can try

Resetting Jquery Select2 Multiple dropdownlist causes a blank item to be selected?

一笑奈何 提交于 2019-12-14 03:17:36
问题 I am using Multiple Select2 plugin in an user registraion page.On clicking the submit button,after the details are saved i am resetting the dropdownlist.The problem is that when i select another item from the dropdownlist a blank item is automatically selected in the dropdownlist Html @Html.DropDownListFor(m => m.MultipleCourseId , Model.MultipleCourseList , "" , new { @class = "form-control select2", @id = "ddlCourseMultiple",@multiple="multiple" }) Calling reset on Jquery Button click $

Select2 event that triggers on any option, selected or not selected?

我的未来我决定 提交于 2019-12-14 03:10:49
问题 Click on 1, 2, 3 in the snippet below. How can I reach originalEvent so the alert open up on the already selected item, the same way as the other options in the list? I've tried the built in events, but I can't seem to find one that triggers on any select in the list, already selected or not. $(".form-control").select2({ templateResult: formatSelect2, }); $(".form-control").on('select2:select', function (evt) { var origEvent = evt.params.originalEvent; if($(origEvent.target).closest('

Select2: loading selected values

老子叫甜甜 提交于 2019-12-14 00:19:01
问题 Im trying to load the selected values from the database into my multiple select box. When I load the option initially from the database, It work perfect. But I would like to add the SELECTED items for this rrecord. I've tried a few approaches which is a bit hacky, like this. var keywordArray = new Array(); keywordArray = test[0].keyword.split(","); for( var x = 0; x < keywordArray.length ; x++){ foundKeyword = $( "select" ).find("option[value="+keywordArray[x]+"]").text(); $('.select2-choices

Select2 formatResult get attributes of option

笑着哭i 提交于 2019-12-13 16:44:18
问题 Get custom data-attribute in select2 with <select> We need the same thing specified in the above link. But, how to get the attributes of option element in formatResult function? 回答1: You could try the following code : $select2.data('placeholder', 'please choose').html(_options).select2({ formatNoMatches: function (term) { return 'There is no "' + term + '" item'; }, formatResult: function(term) { return $(term.element).data('cnt'); }, allowClear: true }); JSBIN 来源: https://stackoverflow.com

closing select2 on click away when closeonselect is false

房东的猫 提交于 2019-12-13 16:14:45
问题 is there a better way to close select2 when you click away? I have it closing with $(document).click(function(event) { if(!$(event.target).hasClass("select2-selection__rendered") && !$(event.target).hasClass("select2-results__option")) { $("#e1").select2('close'); } }); but that seems weird. here is the fiddle http://jsfiddle.net/jEADR/5557/ 来源: https://stackoverflow.com/questions/49466671/closing-select2-on-click-away-when-closeonselect-is-false