Questions tagged [select2-rails]

Rails asset pipeline integration of the jQuery Select2 plugin.

The select2-rails gem integrates the Select2 jQuery plugin with the Rails asset pipeline.

Homepage

120 questions
30
votes
7 answers

Prevent select2 from flipping the dropdown upward

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",…
kjb
  • 3,035
  • 3
  • 23
  • 30
15
votes
3 answers

How do I use select2-rails with simple_form?

This select2 jquery library looks awesome. There is a Rails gem but it is very light on the documentation. I would like to generate a simple multiple drop-down menu, using autocomplete. How do I do that? This is my simple_form_for call: <%=…
7
votes
4 answers

select2-rails gem is not working on Rails4

I have tried given documentation for the select2-rails gem, but my browser console still throws an error. Uncaught TypeError: $(...).select2 is not a function I am using rails 4.0.1& select2-rails 3.5.9.3 My application.js //= require jquery //=…
Prashant4224
  • 1,551
  • 1
  • 14
  • 21
5
votes
2 answers

Select2 doesn't trigger on change/selection of first option

What I am doing: Dynamically adding options to a select box when modal popup opens. And waiting for on change trigger to respond. Observation: It pops up alert box for all options but first. Below is the code. $("#query_product").on("change",…
bill_cosby
  • 145
  • 2
  • 9
5
votes
2 answers

Select2 automatically adding blank value

I'm using select2 for a multiple selector. Currently this is in my HTML file: <%= form.select "page_request_set_ids", @multiautocomplete_set_options.unshift(""), {}, id: "page-request-sets", multiple: true, allowClear: true, data: {placeholder:…
nhyne
  • 405
  • 1
  • 5
  • 18
5
votes
1 answer

acts_as_taggable_on and select2 returning weird results in Active Admin

So I have been playing around with acts_as_taggable_on in active admin, and for the most part everything is working as expected. However, whenever I search for tags, and add an existing tag to a model, it seems to save it as the ID, rather than as…
5
votes
1 answer

How to add placeholder for select2?

Yeah we can add placeholder to select2 like this, $("#e2_2").select2({ placeholder: "Select a State" }); But I need something like this, Here you can see linkedin provides "Type another area of expertise". Means when you select expertise again it…
Ashwini
  • 2,449
  • 2
  • 29
  • 42
4
votes
1 answer

Select2.js - Search input to allow only numbers

I'm struggling with this for a day now, probably is really easy to solve. What I want is the search field to only accept numbers, so I tried something like this: function onlyNumbers(){ $('.select2-search__field').on('keypress', function () { …
Proz1g
  • 1,177
  • 4
  • 16
  • 36
4
votes
1 answer

Select2 submitting value instead of id

I have Rails app, where I'm able to select country from: = f.input :country, label: t("heading.country"), as: :string, input_html: { class: 'select2', data: { allowadd: true, depth: 0, id: @post.location.country.id, url: search_locations_path }…
4
votes
1 answer

collection_select with select2 and bootstrap: undefined is not a function

In a Rails 4.1 app, I have a collection select that is loaded from a hash. I would like to use the select2 boostrap styling, but it doesn't seem to be working. I have included the select2-rails gem, and updated application.js and application.css as…
port5432
  • 5,889
  • 10
  • 60
  • 97
4
votes
0 answers

Trigger select2's 'createSearchChoice' Programmatically

Is there any way to call createSearchChoice programmatically? When the page loads we might have a "name" or an "id", if it's an "id" we can use "initSelection" and that will populate the select2 input with the data coming from the server. However if…
Johnathan Barrett
  • 546
  • 2
  • 7
  • 24
3
votes
2 answers

Select2 takes a long time to load

When I use select2 in rails and reload this entry appears for 1 second Then it goes back to normal like the following picture: This is my code and I have tried placing it in css display hidden and visibility true without any success javascript: …
Samuel D.
  • 199
  • 10
3
votes
0 answers

select2-rails misbehaving on browser-back (displaying twice)

select2-rails gem seems to have problems with the browser-back function in my project: Steps to recreate bug: go to http://methoden-app.herokuapp.com/ click on any link use back button of your browser the select2-selects in the form will have…
thostefa
  • 31
  • 2
3
votes
2 answers

How do I write custom select2 (4.0) matcher which ignores whitespace and dots?

I want to write a custom select2 (versions 4.0) matcher such that dots and whitespaces are ignored when a search is performed. Eg. If one of the option is Dr. R. N. Pandey, I should be able to find Dr. R. N. Pandey just by typing rnp in the search…
abhishek77in
  • 1,848
  • 21
  • 41
3
votes
1 answer

programmatically select select2 options using jquery

I tried below solutions to select one of the listed options