【问题标题】:Insert svg into simple form input将 svg 插入简单的表单输入
【发布时间】:2018-07-23 13:53:42
【问题描述】:

我对简单表单 gem 很陌生,我想使用 SVG 插件自定义输入,例如将电子邮件图片放入输入字段“电子邮件”

这里是svg代码:

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 24 24" xml:space="preserve" width="24" height="24"><title>email 84</title><g class="nc-icon-wrapper" stroke-linecap="square" stroke-linejoin="miter" stroke-width="2" fill="#111111" stroke="#111111"><polyline data-cap="butt" data-color="color-2" fill="none" stroke-miterlimit="10" points="1,3 12,13 23,3 " stroke-linecap="butt"/> <rect x="1" y="3" fill="none" stroke="#111111" stroke-miterlimit="10" width="22" height="18"/></g></svg>

这是我的简单表单代码:

<div class="col-xs-12 col-sm-4 col-sm-offset-4">
  <div class="form-login">
    <p>Welcome !!</p>
     <div class="hr">
    </div>

    <%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
      <%= f.error_notification %>

      <div class="form-inputs">
        <%= f.input :first_name, required: true, autofocus: true, placeholder: "First name" %>
         <%= f.input :last_name, required: true, autofocus: true, placeholder: "Last name" %>
        <%= f.input :email, required: true, autofocus: true, placeholder: "Email Address" %>
        <%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length), placeholder: "Password" %>
        <%= f.input :password_confirmation, required: true, placeholder: "Password" %>
      </div>

      <div class="form-actions">
        <%= f.button :submit, "Sign up", class: "btn btn-danger small-btn width-login" %>
      </div>
    <% end %>

</div>
</div>

我应该把 SVG 代码放在哪里?

谢谢!!

【问题讨论】:

  • 你的意思是用户上传了图片,或者你只是想在表单的某个地方显示它?在后一种情况下,具体在哪里?
  • 我只想在表格中显示!我希望图像在输入中,贴在右边框上。

标签: ruby-on-rails simple-form erb


【解决方案1】:

您可以在输入标签之前放入标签标签

<%= f.label(:email) do %>
  # Here is the SVG
  #Edit
  <%= f.input :email, required: true, autofocus: true, placeholder: "Email Address" %>
<% end %>

编辑: 你应该像How to add a SVG icon within an input?中那样使用css

【讨论】:

  • 它不起作用:图像在输入行之前,我想将图像放在输入中。
  • 请检查编辑
  • 仍然没有多大帮助,很抱歉:图像出现在行前此方法似乎不适用于简单表单 gem。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-15
  • 1970-01-01
  • 2020-11-10
  • 1970-01-01
相关资源
最近更新 更多