简体   繁体   English

如何使用simple_form生成输入[type = date]?

[英]How can I generate input[type=date] with simple_form?

When I do f.input :start_date, as: :date I get 3 select elements (day, month and year). 当我执行f.input :start_date, as: :date我得到3个选择元素(日,月和年)。

I can do f.input :start_date, as: :string to get input[type=text] element, but how can I generate input[type=date] element with simple_form? 我可以做f.input :start_date, as: :string来获取input[type=text]元素,但是如何用simple_form生成input[type=date]元素?

You should specify html5 option: 你应该指定html5选项:

f.input :start_date, as: :date, html5: true

Here is details. 是细节。

HTML 5 date / time inputs are not generated by Simple Form by default, so using date, time or datetime will all generate select boxes using normal Rails helpers. 默认情况下,Simple Form不会生成HTML 5日期/时间输入,因此使用日期,时间或日期时间都会使用普通的Rails助手生成选择框。 We believe browsers are not totally ready for these yet, but you can easily opt-in on a per-input basis by passing the html5 option : 我们认为浏览器尚未完全准备好这些, 但您可以通过传递html5选项轻松地在每个输入的基础上选择

<%= f.input :expires_at, as: :date, html5: true %>

Hopefully this piece of information found in simple_form documentation will solve your problem. 希望simple_form文档中的这些信息可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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