更改rails text_field表单构建器类型 [英] Change rails text_field form builder type

查看:93
本文介绍了更改rails text_field表单构建器类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究HTML5表单中提供的新选项,例如将输入类型声明为email,url和number,如这里

I've been looking at the new options available in HTML5 forms, such as declaring input types as "email", "url", and "number", as described here.

如何将这些与rails表单构建器一起使用?我试过了

How can I use these in conjunction with the rails form builders? I have tried

<% form_for @user do |f| %>
  <%= f.email :email, {:placeholder => 'user@domain.com'} %>
<% end %>

但这不起作用。我也试过了

But that does not work. I've also tried

<% form_for @user do |f| %>
  <%= f.text_field :email, {:placeholder => 'user@domain.com', :type  => :email} %>
<% end %>

但是类型仍然是文本而不​​是被覆盖。是否可能,或者这是否需要在Rails中解决?

But the type is still "text" and not overridden. Is it possible, or is this something that will need to be addressed in Rails itself?

推荐答案

现在有一个 email_field 标签

There is now an email_field tag.

这篇关于更改rails text_field表单构建器类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆