jquery-select2

How to have differents placeholders with two select2

烈酒焚心 提交于 2019-12-24 15:53:41
问题 Test on http://jsfiddle.net/7J8Ag/31/. With : var opts=$("#select1").html(), opts2="<option></option>"+opts; $("select.populate").each(function() { var e=$(this); e.html(e.hasClass("placeholder")?opts2:opts); }); I have correctly two differents "placeholders", but the list in #select0 is the same of #select1. So it's not ok. I don't know, practically, to have two differents "placeholders" in two differents select2. 来源: https://stackoverflow.com/questions/21072525/how-to-have-differents

How to pre-load an array via ajax and use it for select2?

混江龙づ霸主 提交于 2019-12-24 13:16:04
问题 My general problem is that I want to have a Javascript variable which I then use with select2, to prepare the options for a select multiple. I have a fairly large array (7000 objects) and just want to store that once in a variable rather than constantly polling the server with search terms. Here is what I got. The HTML is simply: <input type="hidden" id="group_a" multiple="multiple" placeholder="Select at least two treatments"> Now, when I write the variable directly everything works as

Use AJAX in ng2-select2

随声附和 提交于 2019-12-24 10:57:19
问题 I have many drop-downs in my angular2js project. I am using ng2-select2 for these drop-down. In some dropdown, I need to filter and fetch data from an API as per the string user types into the select2 search box. The plug-in initializes but doesn't fire any AJAX. My code so far: HTML: <select2 [data]="options | async"></select2> Component: import { Component,OnInit } from '@angular/core'; import {Select2OptionData} from 'ng2-select2'; import {AlertService, LTJService} from '../../_services

Onclick change width of dropdown using JavaScript

余生长醉 提交于 2019-12-24 10:55:55
问题 I've below code in which I'm trying to change width of dropdown upon click. I tried with click event but no success. Any help is appreciated. <script> $(function() { $('select') .select2({ placeholder: 'Search Command...', width: '200', multiple: false, data: [{ id: '', text: '' }, { id: 'testing1', text: 'testing1' }, { id: 'testing 1,2,3', text: 'testing 1,2,3gffffff' }], tokenSeparators: ['|'] }) .on('onClick', function() { document.getElementByTagName('select').style.width = '500'; }); })

activate select menu on hover/mouseover using select2

删除回忆录丶 提交于 2019-12-24 06:12:03
问题 I've been looking around the documentation to try find a way to easily activate the select menu on hover , and not only on click . Unfortunately, I cannot seem to find the way to do it (if it exists), and was hoping someone could point me in the right direction? Here is a plnk, http://plnkr.co/edit/GTeyWfOp9aTd1B0Be0Hs?p=preview Thanks all 回答1: Try this: $("#myselect").next(".select2").mouseenter(function() { $("#myselect").select2("open"); }); $(document).on("mouseleave", ".select2-container

activate select menu on hover/mouseover using select2

◇◆丶佛笑我妖孽 提交于 2019-12-24 06:11:02
问题 I've been looking around the documentation to try find a way to easily activate the select menu on hover , and not only on click . Unfortunately, I cannot seem to find the way to do it (if it exists), and was hoping someone could point me in the right direction? Here is a plnk, http://plnkr.co/edit/GTeyWfOp9aTd1B0Be0Hs?p=preview Thanks all 回答1: Try this: $("#myselect").next(".select2").mouseenter(function() { $("#myselect").select2("open"); }); $(document).on("mouseleave", ".select2-container

Select2 get html data attribute

淺唱寂寞╮ 提交于 2019-12-24 06:01:26
问题 I'm using latest select2 version. But stuck at getting <select> html attribute. <select name="category" id="category-select" data-ajax--search="slug" class="select2 form-control m-b-2" multiple> </select> // SCRIPT const opts = { ajax: { url: "/menus/search", delay: 250, data: function (param) { return {q: param.term, page: param.page, category: $(this.element).data('search')}; }, processResults: ({data, total_count}, {page}) => { page = page || 1; return { results: data, pagination: { more:

Select2 get html data attribute

寵の児 提交于 2019-12-24 06:00:56
问题 I'm using latest select2 version. But stuck at getting <select> html attribute. <select name="category" id="category-select" data-ajax--search="slug" class="select2 form-control m-b-2" multiple> </select> // SCRIPT const opts = { ajax: { url: "/menus/search", delay: 250, data: function (param) { return {q: param.term, page: param.page, category: $(this.element).data('search')}; }, processResults: ({data, total_count}, {page}) => { page = page || 1; return { results: data, pagination: { more:

select2 + large number of records

此生再无相见时 提交于 2019-12-24 05:53:14
问题 I am using select2 dropdown. It's working fine for smaller number of items. But when the list is huge (more than 40000 items) it really slows down. It's slowest in IE. Otherwise simple Dropdownlist works very fast, till 1000 records. Are there any workarounds for this situation? 回答1: ///////////////**** Jquery Code *******/////////////// var CompanypageSize = 10; function initCompanies() { var defaultTxtOnInit = 'a'; $("#DefaultCompanyId").select2({ allowClear: true, ajax: { url: "

Hide/Remove and Show/Restore options in a Select2 dropdown box

Deadly 提交于 2019-12-24 04:56:26
问题 I have an issue where I need to hide or remove options from a select2 dropdown when selected. These selections fill a list. I would rather not remove the option because if the user removes it from the freshly populated list then it should return to the dropdown with its place in the order restored. I've tried the following: .select2-results .select2-disabled, .select2-results__option[aria-disabled=true] { display: none; } $('#optionId').prop('disabled', true); With the prop being set in the