加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 使用simple_form和自定义包装器在输入字段旁边

发布时间:2020-12-17 02:07:49 所属栏目:百科 来源:网络整理
导读:我有自定义包装器: config.wrappers :input_group,tag: 'div',class: 'form-group',error_class: 'has-error' do |b| b.use :html5 b.use :placeholder b.optional :maxlength b.optional :pattern b.optional :min_max b.optional :readonly b.use :label,
我有自定义包装器:

config.wrappers :input_group,tag: 'div',class: 'form-group',error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.optional :maxlength
    b.optional :pattern
    b.optional :min_max
    b.optional :readonly
    b.use :label,class: 'control-label'

    b.use :input,class: 'form-control',wrap_with: { tag: 'div',class: 'input-group' }
    b.use :error,wrap_with: { tag: 'span',class: 'help-block' }
    b.use :hint,wrap_with: { tag: 'p',class: 'help-block' }
  end

并输入一个表格:

<%= simple_form_for @event do |f| %>
  ...
  <%= f.input :start_date,as: :string,wrapper: :input_group %>
  ...
<% end %>

它生成html:

<div class="form-group string optional event_start_date">
  <label class="string optional control-label" for="event_start_date">Start date</label>
  <div class="input-group">
    <input class="string optional form-control" type="text" name="event[start_date]" id="event_start_date">
  </div>
</div>

我想在输入元素旁边添加span:

<div class="form-group string optional event_start_date">
  <label class="string optional control-label" for="event_start_date">Start date</label>
  <div class="input-group">
    <input class="string optional form-control" type="text" name="event[start_date]" id="event_start_date">
----> <span class="input-group-addon">TEST</span><----
  </div>
</div>

我怎样才能做到这一点 ? (每个输入元素的跨区文本将不同)

解决方法

如果还有其他人仍在寻找这个,那么提示助手就是这样做的:在输入字段旁边添加一个带有任意文本的元素.在上面的示例中,它看起来像这样:

首先将提示包装元素更改为span

config.wrappers :input_group,error_class: 'has-error' do |b|
  ...
  b.use :hint,class: 'help-block' }
  ...
end

然后在您的视图中调用提示:

<%= simple_form_for @event do |f| %>
  ...
  <%= f.input :start_date,wrapper: :input_group,hint: 'TEST' %>
  ...
<% end %>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读