2015-01-12 33 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

相关问题