Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build select date and year inputs with simple_form

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?

like image 573
Mateusz Urbański Avatar asked Jan 12 '15 20:01

Mateusz Urbański


2 Answers

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

like image 189
Luis Avatar answered Nov 14 '22 21:11

Luis


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
like image 31
trh Avatar answered Nov 14 '22 22:11

trh