jquery-select2

Different display value for selecte text using select2.js

醉酒当歌 提交于 2019-12-01 17:48:19
问题 Trying to implement a custom select dropdown using select2 plugin Is it possible to have the selected value to display only the actual option 'value' instead of the text, so if I selected 'Australian Dollar', the selected text should only display 'AUD' My mark-up looks something like this: <select name="convert-to" id="convert-to"> <option value="AUD" data-currency="AUD">Australian Dollar</option> <option value="USD" selected="selected">US Dollar</option> <option value="JPY">Japanese Yen<

How make select2 placeholder for search input

 ̄綄美尐妖づ 提交于 2019-12-01 17:26:07
How to make placeholder for select2 jQuery plugin. On StackOverflow many answers how to make placeholder there, but they about element's placeholder. I need to specify a placeholder for the search box, see pic. I had the same need and I had ended up writing a small extension for the Select2 plugin. There is a new option for the plugin, searchInputPlaceholder , in order to set a placeholder for the 'search' input field. Add the following code right after the plugin's js file: (function($) { var Defaults = $.fn.select2.amd.require('select2/defaults'); $.extend(Defaults.defaults, {

Select2 4.0.0 Bootstrap theme

最后都变了- 提交于 2019-12-01 17:23:44
In select2 4.0 version there is a theme option. However in the documentation I can't find what does the option mean and how can I create custom theme ( https://select2.github.io/examples.html ) I've found bootstrap 3 theme for select2, but it seems to be working only for 3.5 version. So I could I create custom theme for select2 latest version (4.0)? Basically I need bootstrap 3 styling preferably with LESS file @fk is working on a Bootstrap 3 theme for Select2 4.0.0. https://github.com/select2/select2-bootstrap-theme There is not currently any documentation on creating themes for Select2 4.0.0

How make select2 placeholder for search input

♀尐吖头ヾ 提交于 2019-12-01 15:11:06
问题 How to make placeholder for select2 jQuery plugin. On StackOverflow many answers how to make placeholder there, but they about element's placeholder. I need to specify a placeholder for the search box, see pic. 回答1: I had the same need and I had ended up writing a small extension for the Select2 plugin. There is a new option for the plugin, searchInputPlaceholder , in order to set a placeholder for the 'search' input field. Add the following code right after the plugin's js file: (function($)

Focusing Input after Select2 close event fire

梦想的初衷 提交于 2019-12-01 14:30:26
I read always trigger "change"-event for <select>, even if the select2-option clicked is already selected and as the problem was so close to my issue I asked my question there but no answer provided. My problem is that I have a select-box constructed by Select2 and a text input. What I want to achieve is after Select2 closed (no matter the value is changed or not) my text input become focus . So I did something logically fine as follow: $('#select').select2({placeholder: 'City'}); $('#select') .on('select2-close', function (e) { $('#hey').focus(); }); http://jsfiddle.net/sobhanattar/x49F2/8/

jQuery select2 control - retrieve last selected element

一个人想着一个人 提交于 2019-12-01 09:09:38
I am using jQuery select2 control and I need to implement the following functionality: if the user tries to add a certain element, based on some algorithm, I should delete another (incompatible) element from the selection. I see two ways to achieve that: 1) inhibit automatic sorting of selected values 2) get value of the last selected item and optionally remove the incompatible item from the list For 1) I could not figure how to inhibit auto sorting (both "data" and "values" are ordered after a selection is performed) For 2) I could not find last selected item information anywhere (I expected

Select2 initSelection

≯℡__Kan透↙ 提交于 2019-12-01 08:27:47
I have a problem to set the method initSelection with an ajax call, I returns "undefined". I checked and the ajax call returns the correct result .. I donot understand the method how to set the callback method to make sure that you select 'the preset value. function mediaFormatResult(media) { var markup = "<div class='media-title'>" + media.name + ", " + media.prov + " (" + media.region + ")</div>"; return markup; } function mediaFormatSelection(media) { return media.name +", " + media.prov + " (" + media.region + ")"; } $field = $('#comune'); $($field).select2({ placeholder: "Seleziona il tuo

jQuery select2 control - retrieve last selected element

∥☆過路亽.° 提交于 2019-12-01 05:51:06
问题 I am using jQuery select2 control and I need to implement the following functionality: if the user tries to add a certain element, based on some algorithm, I should delete another (incompatible) element from the selection. I see two ways to achieve that: 1) inhibit automatic sorting of selected values 2) get value of the last selected item and optionally remove the incompatible item from the list For 1) I could not figure how to inhibit auto sorting (both "data" and "values" are ordered after

Select2.js error: Cannot read property 'length' of undefined

感情迁移 提交于 2019-12-01 05:45:34
I am using Select2 jquery plugin and I can't get results with json. When looking json response in browser it looks ok. Like this for example: [{ "id" : "50", "family" : "Portulacaceae " }, { "id" : "76", "family" : "Styracaceae " }, { "id" : "137", "family" : "Dipsacaceae" } ] URL called with ajax in this case is: http://localhost/webpage/json_family.php?term=acac&_=1417999511783 but I can't get that results in select2 input, console says: Uncaught TypeError: Cannot read property 'length' of undefined Here is code: html <input type="hidden" id="select2_family" name="term" style="width:30%" />

Select2 initSelection

二次信任 提交于 2019-12-01 04:17:54
问题 I have a problem to set the method initSelection with an ajax call, I returns "undefined". I checked and the ajax call returns the correct result .. I donot understand the method how to set the callback method to make sure that you select 'the preset value. function mediaFormatResult(media) { var markup = "<div class='media-title'>" + media.name + ", " + media.prov + " (" + media.region + ")</div>"; return markup; } function mediaFormatSelection(media) { return media.name +", " + media.prov +