LoginSignup
0
0

More than 5 years have passed since last update.

simple_formのplaceholderでfont-awesomeをjQueryでささっと表示する

Last updated at Posted at 2017-01-09

個人的なメモ

simple_formのplaceholderにfont-awesomeを表示させるためにCSSにおまじないしても、input_html: => {class: "font-awesome"}みたいなことしても、ブラウザで表示したら&が文字化けして$amp#fX002とか訳の分からない表示になる。

こんなときは、jQuery使ってplaceholder入れ替えたら早い。
ということで、

<%= f.input :email, required: true, autofocus: true, placeholder: "replace to Email",
 input_html: { class: 'font-awesome' }, label: false %>
input.font-awesome {
    font-family: FontAwesome;
    font-style: normal;
    font-weight: normal;
    text-decoration: inherit;
}

こうして

<div class="email>
  <input placeholder="hoge" ...(他省略)>
</div>

      $(".email").find("input").attr("placeholder",$.parseHTML("&#61442; Your Email")[0].data)

こう。

これでばっちり表示される。

ちなみにコードのチートシート

チートシート

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0