2015-01-12 35 views
2

在我的Ruby on Rails應用程序中,我有一些需要輸入來選擇月份和年份的表單。我這樣做是與內置的Rails的select_date輸入:使用simple_form構建選擇日期和年度輸入

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

但現在我想知道有沒有辦法在同一容易simple_form?

回答

2

顯然,一個老問題,但答案是肯定的,你絕對可以做同樣的simple_form。發佈給其他人尋找這個答案。

你會通過date作爲輸入類型,然後仿似select_date的form_for輸入助手,你會經過discard_day

因此,它可能是這樣的:

= f.input :your_date_field, as: :date, discard_day: true 
3

你好閱讀本文件 其他形式的控制值得一提的利益

1.4其他傭工文字區域,密碼字段,隱藏字段,檢索字段,電話字段,日期字段,時間字段,色域,日期時間字段,日期時間局部領域,月田,周田,URL字段,電子郵件領域,一些領域和範圍字段:

<%= 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

多例的例子在這裏:

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

+1

但我的解決方案完美地工作。我也使用date_select,但現在我想找到與simple_form完全相同的解決方案。 –

+0

簡單是紅寶石寶石... – Luis

+0

但文檔oficialy https://github.com/plataformatec/simple_form使用自定義輸入o使用日期輸入,問候 – Luis

相關問題