jquery-select2

jquery select2: error in getting data from php-mysql

北城以北 提交于 2019-11-27 06:28:56
问题 I am testing select2 plugin in my local machine. But for some reason. it is not collecting the data from database. I tried multiple times but not able to find the issue. Below are the code . <div class="form-group"> <div class="col-sm-6"> <input type="hidden" id="tags" style="width: 300px"/> </div> </div> <script type="text/javascript"> var lastResults = []; $("#tags").select2({ multiple: true, placeholder: "Please enter tags", tokenSeparators: [","], initSelection : function (element,

How to use Select2 with JSON via Ajax request?

牧云@^-^@ 提交于 2019-11-27 06:02:55
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 { results: data.itemName, more: more }; } }, formatResult: function (data, term) { return data; }, formatSelection:

Is it possible to paste a list to a select2 field and match each item in the list?

旧巷老猫 提交于 2019-11-27 05:38:41
问题 I am using Select2 to manage large lists of data. Users have expressed a desire to be able to paste a list to the Select2 field in order to select various items at once instead of manually entering and matching each item in the list. I have attempted to use tokenSeparators to separate the items in the list. This and the demo on tokens in the documentation lead me to believe that what I am hoping to do is possible, but so far I have had no joy. The code I use to instantiate Select2 is: $(

Select2 start with input field instead of dropdown

自古美人都是妖i 提交于 2019-11-27 05:32:25
问题 I use the js library select2. This is a screenshot of what I have now: Start: Click on dropdown: Now is it possible to have an input field to start with and not directly a dropdownlist? I know it's possible because you can find it on the select2 site. An example is this: But the documentation is very brief. This is what I have now: <input type="text" name="questions[question1]" id="question1" class="question1" style="width:500px"/> function createQuestionTags(data, question_number){ $("

Using bootstrap select2 with JqGrid form

我与影子孤独终老i 提交于 2019-11-27 04:56:47
I am trying to implement bootstrap select2 with jqgrid form but can seem to get it right. on the colmodel of the jqgrid declaration I have: {name: 'staff', index: 'staff', width: 31, formoptions: {elmprefix: '(*) '}, editable: true, editrules: {required: true}, edittype: 'select', editoptions: {value: staff, dataInit: function(element) { $(element).width(260).select2(); } } }, The options are there and bootstrap classes are inserted into the element, <select id="staff" class="select2-offscreen FormElement" role="select" but all I am getting is a blank space for the select. See image below. Can

Select2: How to prevent tags sorting

人走茶凉 提交于 2019-11-27 04:33:55
问题 When user selects many items (tags), they are automatically sorted alphabetically. How to prevent automatic sort and keep user's order using Select2 4.0? Update: The mentioned "possible dublicate question" is for the older version of Select2 v3... I ask about version 4... It differs form older ones and mentioned answers dosn't solve the problem. 回答1: I've found a solution that works with Select2 v4. It changes the order of items - item selected by user are moved to the end. $("select")

Select2: Hide certain options dynamically

时光怂恿深爱的人放手 提交于 2019-11-27 04:32:45
问题 Basically what I'm looking for is the ability to hide options from the dropdown of select items. So, technically they would still be options, but you just wouldn't be able to click them since they're hidden. I've looked through the docs and have found things related to disabling, unfortunately I very specifically want the ability to hide items. Does anyone have advice on how to accomplish this? Were it possible to do something like have the select do some specific mapping between the original

Select2 open dropdown on focus

强颜欢笑 提交于 2019-11-27 04:25:30
问题 I have a form with multiple text inputs and some select2 elements. Using the keyboard to tab between fields works fine - the Select2 element behaves like a form element and receives focus when tabbing. I was wondering if it is possible to open the dropdown when the Select2 element gets focus. Here's what I've tried so far: $("#myid").select2().on('select2-focus', function(){ $(this).select2('open'); }); But using this code makes the dropdown to open again after a selection is made. 回答1:

Select2 performance for large set of items

爷,独闯天下 提交于 2019-11-27 04:16:22
问题 I'm using select2 jquery plugin with twitter bootstrap. It's working fine for smaller number of items. But when the list is huge (more than 1500 items) it really slows down. It's slowest in IE. Normal Dropdownlist works very fast with more than 1500 items. Are there any workarounds for this situation? 回答1: You can make this work good even in IE8 with paginating the suggestions, Code: // Function to shuffle the demo data function shuffle(str) { return str .split('') .sort(function() { return 0

Attach click-event to element in .select2-result

前提是你 提交于 2019-11-27 03:45:44
I'm looking for a way to attach a click-event to a select2-result-item. I've gone ahead and formatted both result and selection via function format(state) { if (!state.id) return state.text; // optgroup return state.text + " <i class='info'>link</i>"; } to add an "info"-icon I'm now trying to attach a simple click-event to the .info-element but can't get this to work: $('.info').on('click', function(event){ event.preventDefault(); alert("CLICK"); $('#log').text( "clicked" ); }); Any help? Anyone with a similar problem? Is this possible at all? I prepared a jsFiddle at: http://jsfiddle.net