jquery-select2

Getting select2 to work with active admin

大兔子大兔子 提交于 2019-11-30 05:24:54
问题 I am working with an app with Active Admin and needed to select multiple values from a select input, I have added the Select2 gem which adds all the relevant the JS and CSS with no issues but for some reason the select boxes seem to change their appearance slightly but not to the ful Select2 appearance, upon inspection the JS doesn't look like its added all the correct classes...... any ideas? Here is my code: active_admin.css.scss //= require select2 @import "active_admin/mixins"; @import

Rails acts-as-taggable-on with select2 (and simple_form)

放肆的年华 提交于 2019-11-30 05:09:06
问题 I would like to have a select2 dropdown of tags, where i could select multiple existing tags and add new ones. I have tried many different ways and i either don't get select2 box working or only one value is passed (last one). This is closest i got (passes last value): <%= f.input :tag_list, collection: @model.tags.map { |t| t.name }, input_html: { :style=> 'width: 300px', class: "taggable", data: { placeholder: "Tags" }} %> 回答1: As I mentioned before, normal select2 library now uses only

Programmatically set the value of a Select2 ajax

天大地大妈咪最大 提交于 2019-11-30 04:26:34
I have a Select2 auto-complete input (built via SonataAdmin), but cannot for the life of me figure out how to programmatically set it to a known key/value pair. There's a JS Fiddle here that shows roughly what I have. What I want to know is what function I can attach to the button so that the Select2 field shows the text "NEW VALUE" to the user, and the Select2 field will submit a value of "1" when the form is sent to the server I have tried all sorts of combinations of jQuery and Select2 data and val methods, called against various inputs on the page, but nothing seems to work... surely there

Fill Select2 dropdown box from database in MVC 4

好久不见. 提交于 2019-11-30 04:12:50
I need help writing the jquery/ajax to fill a Select2 dropdown box. For those who don't know what Select2 is, it is a javascript extension to provide Twitter Bootstrap looks and search / type-ahead functionality to an html select list dropdown box. For more information look at the examples here: Select2 Github page UPDATED - Solved! So I finally put this all together, and the solution to my problems was that I was missing functions to format the results and the list selection. The code below produces a functioning Select2 dropbox with type-ahead perfectly. Json Method on Controller: public

Display result matching optgroup using select2

非 Y 不嫁゛ 提交于 2019-11-30 04:06:14
问题 I'm using select2 with Bootstrap 3. Now I would like to know whether it is possible to display all optgroup items if the search matches the optgroup name while still being able to search for items as well. If this is possible, how can I do it? 回答1: Actually found the solution by modifying the matcher opt $("#myselect").select2({ matcher: function(term, text, opt){ return text.toUpperCase().indexOf(term.toUpperCase())>=0 || opt.parent("optgroup").attr("label").toUpperCase().indexOf(term

Select2 - Ajax search - remember last results

倾然丶 夕夏残阳落幕 提交于 2019-11-30 03:32:29
问题 I am using Select2 3.5.1. With this plugin I can successfully load remote data. However I am here today to ask a question to improve this search. Here is the step-by-step to understand what I would like to do: Setup a Select2 with remote data loading (using ajax). Click on the Select2 input and search for something. The loading will appear and after some seconds you will see a list of results. Click on one of the results listed - the box of results will then disappear. If you click again on

Select2 and initSelection callback

陌路散爱 提交于 2019-11-30 03:27:11
On page load, I'm trying to use initSelection to select ID 60 (specified value of the input field) . I can't seem to get it to work properly. The PHP scripts work great and return the correct values, but how do I get the JS to do the callback correctly? JavaScript: $(document).ready(function() { $('#editAlbumArtistId').select2({ placeholder: 'Search names', ajax: { url: "/jQueryScripts/jQuerySelectListArtists.php", dataType: 'json', quietMillis: 100, data: function (term, page) { return { term: term, //search term page_limit: 10 // page size }; }, results: function (data, page) { return

An event is interfering with Select2 plugin's ajax-retrieved results

折月煮酒 提交于 2019-11-30 02:42:33
问题 I'm using Igor Vaynberg's Select2 jQuery plugin with the Infinite Scroll with Remote Data option to make an autocomplete search box for my website. The AJAX is working great and the results are showing up, but they are unselectable -- the change event is never fired and when you click on a result, nothing happens. There are also no errors showing up in the Chrome console, so I think it's not a syntax error, rather the plugin is mistaking it for a disabled select box. EDIT: having tried a

Prevent select2 from flipping the dropdown upward

笑着哭i 提交于 2019-11-30 00:11:14
As per title, is there a way to force select2 to always create a dropdown instead of a drop-up? There also appears to be some javascript that is either causing the flip when you scroll above the dropdown, adding a new CSS class "select2-drop-above", or both. EDIT: I should've specified that I'm pulling the library in via select2-rails. I'm hoping there is a way around this that doesn't involve pulling the whole select2 lib in myself and editing the select2.js file directly. Modifying the plugin is not preferred as you mention. I had a similar issue and couldn't find an way to use select2

Is there any way to check if an element has jquery select2 already applied to it?

ⅰ亾dé卋堺 提交于 2019-11-30 00:09:20
问题 I want to apply select2 to a bunch of jquery elements on the page that all have the same class name but it looks like if i call select2() on an element that already has had a select2() called on it then it blows up. here is my code $('.MyDropdowns').each(function (i, obj) { $(obj).select2({ width: "455px" }); }); so I want something like: $('.MyDripdowns').each(function (i, obj) { if (!$(obj).HasSelect2Initiatized) { $(obj).select2({ width: "455px" }); } }); Does anything like this exist? 回答1