6

In my Ruby on Rails application I have some form that needs inputs to select month and year. I do this with built in Rails select_date input:

 = select_date @date, :order => [ :month, :year], :discard_day => true

But now I want to know is there any way to the same easy with simple_form?

Mateusz Urbański
  • 7,352
  • 15
  • 68
  • 133

2 Answers2

5

Hello read a this documentation

1.4 Other Helpers of Interest Other form controls worth mentioning are textareas, password fields, hidden fields, search fields, telephone fields, date fields, time fields, color fields, datetime fields, datetime-local fields, month fields, week fields, URL fields, email fields, number fields and range fields:

<%= text_area_tag(:message, "Hi, nice site", size: "24x6") %>
<%= password_field_tag(:password) %>
<%= hidden_field_tag(:parent_id, "5") %>
<%= search_field(:user, :name) %>
<%= telephone_field(:user, :phone) %>
<%= date_field(:user, :born_on) %>
<%= datetime_field(:user, :meeting_time) %>
<%= datetime_local_field(:user, :graduation_day) %>
<%= month_field(:user, :birthday_month) %>
<%= week_field(:user, :birthday_week) %>
<%= url_field(:user, :homepage) %>
<%= email_field(:user, :address) %>
<%= color_field(:user, :favorite_color) %>
<%= time_field(:task, :started_at) %>
<%= number_field(:product, :price, in: 1.0..20.0, step: 0.5) %>
<%= range_field(:product, :discount, in: 1..100) %>

http://guides.rubyonrails.org/form_helpers.html

and more example examples here:

http://apidock.com/rails/ActionView/Helpers/DateHelper/date_select

Luis
  • 535
  • 2
  • 14
  • 1
    But my solution works perfectly. I also use date_select but now I want to find solution to have exactly the same with simple_form. – Mateusz Urbański Jan 12 '15 at 21:04
  • but documentation oficialy https://github.com/plataformatec/simple_form using a custom input o use a date inputs, regards – Luis Jan 12 '15 at 21:08
  • other solution is using a html select and jquery, http://stackoverflow.com/questions/16681875/how-to-get-the-value-of-the-date-using-bootstrap-datepicker <-- read this – Luis Jan 12 '15 at 21:10
5

Obviously an old question but the answer is YES, you absolutely can do the same with simple_form. Posted for others looking for this answer.

You'll pass date as the input type and then rather like the select_date form_for input helper, you'll pass discard_day

So it might look like this:

= f.input :your_date_field, as: :date,  discard_day: true
trh
  • 7,186
  • 2
  • 29
  • 41