简体   繁体   中英

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?

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>');
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM