简体   繁体   中英

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 )

But I'd like to get the Bootstrap 3 envelope Glyphicon in front of the text. I'm brand new to Rails as of this week, and haven't been able to find help for this idea elsewhere. 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. Thanks to anyone with advice!

The HTML placeholder attribute only accepts plain text. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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