Trinity76
Trinity76

Reputation: 665

Rails: custom drop down list for search

I use Rails 5.1 and I have two dropdown boxes with 1) years and 2) months. Everything's working fine!

Now I want to add an option "All Months" to the months-dropdown list.

my index view:

<%= form_tag jobs_path, method: :get do %>
  <%= select_year(Date.today, {:prompt => "Year",:start_year => DateTime.now.year,:end_year => DateTime.now.year - 7, prefix: 'select'},{:field_name => 'year', :id => 'start-year'}) %>
  <%= select_month(Date.today, {:prompt => "month",use_short_month: true, prefix: 'select'},{:field_name => 'month', :id => 'start-month'}) %>
  <%= submit_tag("Filter Jobs", :id=>"button", :class=>"Test", :name=>"submit") %>
<% end %>

In the documentation of select_month I can't see an option to add "All months".

How can I add "All month" to the months-dropdown list?

Upvotes: 0

Views: 98

Answers (1)

Anand
Anand

Reputation: 6531

you can achieve this by using javascript, you need to add extra option at the time of document_loaded here:-

$(document).ready(function(){
  $('#start-month').append('<option value="all" selected="selected">All</option>');
})

Upvotes: 1

Related Questions