jquery-select2

Disable select2 plugin in JQuery dropdown

筅森魡賤 提交于 2019-12-08 03:41:46
问题 I am getting the values from json and displaying it in a popup. I need to disable that option which i am getting from json. How can i do that? I tried normal jQuery but It doesn't work. I tried disabled true that also not working. Please give solution. 回答1: From the select2 docs In case that you need to disable certain options so that they can't be selected by the select2 interface, you can now pass in disabled: true with your data. Please note: This also works for incoming values from ajax.

Check/Uncheck - ifChecked not working

心不动则不痛 提交于 2019-12-08 03:40:28
问题 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"

how to get the data-* value of a selected option in select2?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 03:33:16
问题 This is like a second part of this topic and right now I need to be able to read dynamic data-* properties from one select to the other. What this mean? First take a look to the following image: What you're seeing there is what the following code does: // This turn 1st and 3rd into select2 $('#module, #conditions').select2(); // This turn 2nd into select2 using data from a datasource $('select#fields').select2({ placeholder: 'Select a field', data: data.fields }); As I posted in the

Add decorator to data adapter in Select2 version 4.x

会有一股神秘感。 提交于 2019-12-08 02:07:02
问题 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

formatSelection not working in select2.js

最后都变了- 提交于 2019-12-08 01:04:32
问题 I am using select2.js to populate the field with multiple values using ajax call. Below is the code that I am using. HTML <input id="id_test_name" class="form-control"> Script <script type="text/javascript"> $("#id_test_name").select2({ placeholder: "Search for an Item", minimumInputLength: 2, ajax: { url: "/resourse/?format=json&name=xyz", dataType: 'json', quietMillis: 100, data: function (term, page) { return { option: term }; }, results: function (data, page) { return { results: $.map

how to let jquery select2 disable one option dynamically?

我怕爱的太早我们不能终老 提交于 2019-12-07 18:05:15
问题 I have some multiselect and i use jquery select2.I want to disable one option in other multiselect when this option is selected in one multiselect. i write this code,but it does work. $("select.multiselect").on("change", function(e) { if(e.added){ for(var i=0;i<this.options.length;i++){ var vals = $(this).select2("val"); for(var j=0;j<vals.length;j++){ if(this.options[i].value===vals[j]){ this.options[i].selected=true; } } }; } if(e.removed){ for(var i=0;i<this.options.length;i++){ if(this

Firing event when user clicks no matches found jquery plugin select2

百般思念 提交于 2019-12-07 15:48:37
问题 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???? 回答1: Hope my solution helps with your problem: *Select2 configuration var $select2 = $('

Disable select2 plugin in JQuery dropdown

风流意气都作罢 提交于 2019-12-07 15:07:20
I am getting the values from json and displaying it in a popup. I need to disable that option which i am getting from json. How can i do that? I tried normal jQuery but It doesn't work. I tried disabled true that also not working. Please give solution. Jay Rizzi From the select2 docs In case that you need to disable certain options so that they can't be selected by the select2 interface, you can now pass in disabled: true with your data. Please note: This also works for incoming values from ajax. When attached to a element, Select2 will respect its elements' disabled property. $( document )

How to prevent deleting of tags from select2

[亡魂溺海] 提交于 2019-12-07 14:16:40
问题 I've created a select2 widget with tags:true . Is there a way to prevent the deletion of tags by click on the selected item in the drop down, so that the tag only can be removed by clicking the cross in the tag? 回答1: You can use the event select2:unselecting to cancel the tag deletion from the item, eg $(".js-example-tags").select2({ tags: true }).on("select2:unselecting", function (e) { // check if originalEvent.currentTarget.className is "select2-results__option" (in other words if it was

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

随声附和 提交于 2019-12-07 14:11:53
问题 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). 回答1: This