text_field 的类型属性
我有这样的代码:
<%= f.text_field :email, :type => "email", :placeholder => "[email protected]" %>
这样人们就可以使用电子邮件键盘而不是 ASCII 键盘在 iPhone 上输入电子邮件。但是,输出是:
<input id="user_email" name="user[email]" placeholder="[email protected]" size="30" type="text" />
应该是:
<input id="user_email" name="user[email]" placeholder="[email protected]" size="30" type="email" />
我也希望将其用于 tel
类型,以便人们获得电话号码键盘。
有没有办法强制Rails使用email
类型而不是text
,或者我必须直接使用HTML?谢谢
I have this code:
<%= f.text_field :email, :type => "email", :placeholder => "[email protected]" %>
So people can enter their email on an iPhone with the email keyboard instead of the ASCII keyboard. However, the output is:
<input id="user_email" name="user[email]" placeholder="[email protected]" size="30" type="text" />
which should be:
<input id="user_email" name="user[email]" placeholder="[email protected]" size="30" type="email" />
I also want this for the tel
type, so people get the telephone number keyboard.
Is there a way to force Rails to use the email
type instead of text
, or must I use HTML directly? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用当前的帮助程序 (http://api. rubyonrails.org/classes/ActionView/Helpers/FormHelper.html)“返回专为访问指定属性而定制的“文本”类型的输入标记...”
我会编写一个帮助程序来使您的代码更好。您可以只使用所需的 HTML 和选项编写一些内容,也可以添加一些内容以与 FormBuilder 一起使用,如下面的代码片段。
It is not possible to do this with the current helpers (http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html) "Returns an input tag of the "text" type tailored for accessing a specified attribute..."
I'd write a helper to keep your code nicer. You could just write something with the HTML and options you need, or you could add something to work with FormBuilder like the snippet below.
实际上,Rails 3 中有用于此目的的表单助手:
Phone_field 和 email_field 的工作方式与 text_field 类似,但按照您的预期设置其类型属性。
Actually, in Rails 3 there are form helpers for this purpose:
telephone_field and email_field work just like text_field, but set their type attributes as you would expect..