0

I have a form search like this:

filter

When i used select2 for select#search_topic, this become:

filter_error

This is my select2 code:

<% content_for :head do %>
  <script type="text/javascript">
$(document).ready(function() {
  $('#search_topic').select2();
});
  </script>
<% end %>

My form:

<%= form_tag({ controller: 'questions', action: 'search_filter' }, method: 'get', class: 'form-inline') do %>
  <%= label_tag 'search_topic', 'Filter:', class: 'label_search' %> 
  <%= select_tag 'search_topic', options_from_collection_for_select(current_user.get_topics, :id, :name), :prompt => "Select topic" %>
  <%= select_tag 'search_type', options_from_collection_for_select(@question_types, :id, :name), :prompt => "Select type question" %>
  <%= submit_tag "Search", name: nil, class: 'btn' %>
<% end %>

I have copied select2.js and select2.css.scss(change name from selec2.css) to vendor/javascript and vendor/stylesheet.

And I changed url('select2.png') in scss file to image_url("select2.png"). I also copied select2.png to app/assets/images.

In application.js i have //= require select2. In application.css.scss i have @import "select2";. What is wrong with my code?

Community
  • 1
  • 1
Thanh
  • 8,219
  • 5
  • 33
  • 56

1 Answers1

0

You should be able to set a default width for the select.

http://ivaynberg.github.com/select2/index.html

search page for width

also if you add :multiple => "" it uses the multiple text box version

jrich
  • 75
  • 6
  • It didn't work, I did it before. But I found the answer in [this question](http://stackoverflow.com/questions/12683907/set-the-width-of-select2-input-through-angular-ui-directive) + set the first item for dropdown list. – Thanh Jan 20 '13 at 14:08