jquery-select2

How to use placeholder as default value in select2 framework

最后都变了- 提交于 2019-11-26 18:14:40
问题 To get the chosen value of a select2 I'm using: var x = $("#select").select2('data'); var select_choice = x.text The problem is this throws an error if not value has been selected and I was wondering if there was any way to make it return the placeholder if no option is selected 回答1: You have to add an empty option (i.e. <option></option> ) as a first element to see a placeholder. From Select2 official documentation : "Note that because browsers assume the first option element is selected in

Get Selected value from Multi-Value Select Boxes by jquery-select2?

痴心易碎 提交于 2019-11-26 18:04:25
问题 I am using Select2 Jquery to bind my dropdown which is used for multiple selection . I am using select2 jquery. It's working fine, I can bind my dropdown but I need to get the selected value from my multi-value selector. I am looking for method to get value which is supported by select2 Jquery. it might be having a function get selected value. my drop down binding code $(".leaderMultiSelctdropdown").select2( { maximumSelectionSize: 4 }); 回答1: alert("Selected value is: "+$("

Select2 4.0 - Push new entry after creation

那年仲夏 提交于 2019-11-26 17:48:22
问题 I have been using Select2 4.0.0-rc.1 for a couple of weeks (using the ajax adapter) and I am trying to find a way to "push" data after it has been initialized. Within the dropdown list, I have the choice to select an entry in the list (using ajax ) add a free entry (using createTag ) add a new entry If I select "add a new entry", I can fill out a form, and once saved, the new data must be shown as a selected entry. If I push data using select2_existing.select2( { data: data } ).val( 4 ); it

Reset select2 value and show placeholder

◇◆丶佛笑我妖孽 提交于 2019-11-26 17:30:28
问题 How do I set the placeholder on value reset by select2. In my example If locations or grade select boxes are clicked and my select2 has a value than the value of select2 should reset and show the default placeholder. This script is resetting the value but won't show the placeholder $("#locations, #grade ").change(function() { $('#e6').select2('data', { placeholder: "Studiengang wählen", id: null, text: '' }); }); $("#e6").select2({ placeholder: "Studiengang wählen", width: 'resolve', id:

Select2() is not a function

依然范特西╮ 提交于 2019-11-26 16:48:40
问题 So i have downloaded select2 i have "installed it" by putting it into my folder and then loaded it on my site when i check the console (where i can see all of the scripts being loaded) i can see the file select2.js I went to their documentation and copied it and added $("#e9").select2(); However when i load the page i get the following error: TypeError: $(...).select2 is not a function $("#e9").select2(); Have anyone else experianced anything like this? Additional information here is my

Selectable optgroups in Select2

不问归期 提交于 2019-11-26 16:17:14
问题 I want to create multilevel select2 options with indentation but I don't want to use optgroup elements for this because I want to allow select also main categories. Is there any way to style if for select2? My raw HTML select looks like this: <select class="js-select-multiple"> <option class="l1">Option 1</option> <option class="l2">Suboption 1</option> <option class="l2">Suboption 2</option> <option class="l2">Suboption 3</option> <option class="l1">Option 2</option> ... </select> <script>$(

Initialising select2 created dynamically

吃可爱长大的小学妹 提交于 2019-11-26 15:55:45
问题 I have a select2 drop-down for which I provide a matcher function. It is initialised like this on initial page load: jQuery(document).ready(function() { jQuery(".my_select2").select2({ matcher: function(term, text) {...} }); }); That works find on initial page load. Now, I have additional drop-downs ( select elements created dynamically (pulled in via AJAX, i.e. jQuery(match).load(url) . These additional drop-downs do not get intialised as select2 widgets, which is understandable, even though

JQuery Select2 - How to select all options

て烟熏妆下的殇ゞ 提交于 2019-11-26 15:33:08
问题 I'm using jQuery select2 multi select dropdown. I need to select all options in a dropdown from code. Basically there is a Select All checkbox on which this functionality has to be implemented, I want to select/deselect options from this checkbox. 回答1: There is a description in thread on github. Quoting (https://github.com/ivaynberg/select2/issues/195#issuecomment-13489140 by MortadaAK) which allows you to select everything on ctrl+a $(document).on("keypress",".select2-input",function(event){

select2 changing items dynamically

余生长醉 提交于 2019-11-26 15:23:34
问题 I have two selects that are linked: Each value of the first select determines which items will be displayed in the second select. The values of the second select are stored in a two-dimension array: [ [{"id":1,"text":"a"}, {"id":2,"text":"b"},...], [{"id":"1a","text":"aa"},{"id":"1b","text":"ba"},...], ... ] The first select value determines the index to be used to populate the second select. So in a 'change' event on the first I should be able to modify the items select-two contains. Reading

How to use Select2 with JSON via Ajax request?

依然范特西╮ 提交于 2019-11-26 11:49:44
问题 My Select2 3.4.5 is not working with JSON data. Here is my input box on HTML: <input class=\'form-control col-lg-5 itemSearch\' type=\'text\' placeholder=\'select item\' /> …and my JavaScript $(\".itemSearch\").select2({ placeholder: \"Search for an Item\", minimumInputLength: 2, ajax: { url: \"/api/productSearch\", dataType: \'json\', quietMillis: 100, data: function (term, page) { return { option: term }; }, results: function (data, page) { var more = (page * 10) < data.total; return {