简体   繁体   English

在Slim / Ruby on Rails表单中添加Bootstrap Glyphicon作为占位符

[英]Adding Bootstrap Glyphicon in Slim/Ruby on Rails form as a placeholder

As of right now, the code for the relevant section: 截至目前,相关部分的代码:

= form_for(resource, as: resource_name, url: registration_path(resource_name), html:{id:'registration-form'}) do |f|
    = devise_error_messages!

    div style="padding:4px"
            = f.email_field :email, autofocus: true, placeholder: "Email address", class:"form-control", style:"height:60px"

And the output is looking like this, which I think is pretty okay: 输出看起来像这样,我认为还可以:

电子邮件地址表格
(source: trillian.im ) (来源: trillian.im

But I'd like to get the Bootstrap 3 envelope Glyphicon in front of the text. 但是我想在文字前面添加Bootstrap 3信封Glyphicon。 I'm brand new to Rails as of this week, and haven't been able to find help for this idea elsewhere. 截止到本周为止,我是Rails的新手,但在其他地方找不到该想法的帮助。 It looks like this post is very close to what I want to do, but I'm not sure how to do that against the f.email_field tag. 看起来这篇帖子与我想做的非常接近,但是我不确定如何针对f.email_field标签执行此操作。 Thanks to anyone with advice! 感谢任何人的建议!

The HTML placeholder attribute only accepts plain text. HTML占位符属性仅接受纯文本。 You can't put any tags in there, which is what you would need in order to do what you want. 您不能在其中放置任何标签,这是您执行所需操作所需要的。

You can try putting the icon behind or beside your text field so that it appears to be a place holder instead. 您可以尝试将图标放在文本字段的后面或旁边,以使其看起来像是占位符。

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

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